forked from TrueCloudLab/frostfs-node
Evgenii Stratonikov
2d5d4093be
Pick up changes from TrueCloudLab/frostfs-sdk-go#198. gopatch: ``` @@ var user expression @@ -address.StringToUint160(user.EncodeToString()) +user.ScriptHash() ``` Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
35 lines
971 B
Go
35 lines
971 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, err := id.ScriptHash()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
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("could not get integer stack item from stack item (%s): %w", balanceOfMethod, err)
|
|
}
|
|
return amount, nil
|
|
}
|