Skip to content

Commit

Permalink
feat: replace get_account_balance sql function call by inline query (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag authored Jan 30, 2025
1 parent 8272038 commit 2fd189b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion internal/storage/ledgerstore/balances.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,16 @@ func (store *Store) GetBalance(ctx context.Context, address, asset string) (*big
type Temp struct {
Balance *big.Int `bun:"balance,type:numeric"`
}

v, err := fetch[*Temp](store, false, ctx, func(query *bun.SelectQuery) *bun.SelectQuery {
return query.TableExpr("get_account_balance(?, ?, ?) as balance", store.name, address, asset)
return query.
ModelTableExpr(MovesTableName).
ColumnExpr("(post_commit_volumes).inputs - (post_commit_volumes).outputs as balance").
Where("account_address = ?", address).
Where("asset = ?", asset).
Where("ledger = ?", store.name).
Order("seq desc").
Limit(1)
})
if err != nil {
return nil, err
Expand Down

0 comments on commit 2fd189b

Please sign in to comment.