frostfs-node/pkg/morph/client/balance/balanceOf.go
Ekaterina Lebedeva 24054cf6f4
All checks were successful
Tests and linters / Run gofumpt (push) Successful in 48s
Vulncheck / Vulncheck (push) Successful in 1m37s
Pre-commit hooks / Pre-commit (push) Successful in 2m52s
Build / Build Components (push) Successful in 2m47s
Tests and linters / gopls check (push) Successful in 3m18s
Tests and linters / Staticcheck (push) Successful in 3m30s
Tests and linters / Tests with -race (push) Successful in 3m37s
Tests and linters / Lint (push) Successful in 4m27s
Tests and linters / Tests (push) Successful in 4m47s
OCI image / Build container images (push) Successful in 6m53s
[#1618] pkg: Refactor user.ID.ScriptHash() usage
`user.ID.ScriptHash()` does not return an error anymore.

Signed-off-by: Ekaterina Lebedeva <ekaterina.lebedeva@yadro.com>
2025-01-30 13:18:37 +00:00

32 lines
918 B
Go

package balance
import (
"fmt"
"math/big"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
)
// BalanceOf receives the amount of funds in the client's account
// through the Balance contract call, and returns it.
func (c *Client) BalanceOf(id user.ID) (*big.Int, error) {
h := id.ScriptHash()
invokePrm := client.TestInvokePrm{}
invokePrm.SetMethod(balanceOfMethod)
invokePrm.SetArgs(h)
prms, err := c.client.TestInvoke(invokePrm)
if err != nil {
return nil, fmt.Errorf("test invoke (%s): %w", balanceOfMethod, err)
} else if ln := len(prms); ln != 1 {
return nil, fmt.Errorf("unexpected stack item count (%s): %d", balanceOfMethod, ln)
}
amount, err := client.BigIntFromStackItem(prms[0])
if err != nil {
return nil, fmt.Errorf("get integer stack item from stack item (%s): %w", balanceOfMethod, err)
}
return amount, nil
}