From 03f52bca0168380dcc54ead2684bab7207187141 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Wed, 28 Oct 2020 16:01:29 +0300 Subject: [PATCH] [#122] Return big.Int in `balanceOf` function Signed-off-by: Alex Vanin --- pkg/morph/client/balance/balanceOf.go | 8 +++++--- pkg/morph/client/balance/wrapper/balanceOf.go | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/pkg/morph/client/balance/balanceOf.go b/pkg/morph/client/balance/balanceOf.go index 028fca0f9..52a001410 100644 --- a/pkg/morph/client/balance/balanceOf.go +++ b/pkg/morph/client/balance/balanceOf.go @@ -1,6 +1,8 @@ package balance import ( + "math/big" + "github.com/nspcc-dev/neofs-node/pkg/morph/client" "github.com/pkg/errors" ) @@ -14,7 +16,7 @@ type GetBalanceOfArgs struct { // GetBalanceOfValues groups the stack parameters // returned by "balance of" test invoke. type GetBalanceOfValues struct { - amount int64 // wallet funds amount + amount *big.Int // wallet funds amount } // SetWallet sets the wallet script hash @@ -24,7 +26,7 @@ func (g *GetBalanceOfArgs) SetWallet(v []byte) { } // Amount returns the amount of funds. -func (g *GetBalanceOfValues) Amount() int64 { +func (g *GetBalanceOfValues) Amount() *big.Int { return g.amount } @@ -41,7 +43,7 @@ func (c *Client) BalanceOf(args GetBalanceOfArgs) (*GetBalanceOfValues, error) { return nil, errors.Errorf("unexpected stack item count (%s): %d", c.balanceOfMethod, ln) } - amount, err := client.IntFromStackItem(prms[0]) + amount, err := client.BigIntFromStackItem(prms[0]) if err != nil { return nil, errors.Wrapf(err, "could not get integer stack item from stack item (%s)", c.balanceOfMethod) } diff --git a/pkg/morph/client/balance/wrapper/balanceOf.go b/pkg/morph/client/balance/wrapper/balanceOf.go index 48b7a413d..fddd5f0c4 100644 --- a/pkg/morph/client/balance/wrapper/balanceOf.go +++ b/pkg/morph/client/balance/wrapper/balanceOf.go @@ -1,16 +1,18 @@ package wrapper import ( + "math/big" + "github.com/nspcc-dev/neofs-api-go/pkg/owner" "github.com/nspcc-dev/neofs-node/pkg/morph/client/balance" ) // BalanceOf receives the amount of funds in the client's account // through the Balance contract call, and returns it. -func (w *Wrapper) BalanceOf(id *owner.ID) (int64, error) { +func (w *Wrapper) BalanceOf(id *owner.ID) (*big.Int, error) { v, err := owner.ScriptHashBE(id) if err != nil { - return 0, err + return nil, err } args := balance.GetBalanceOfArgs{} @@ -18,7 +20,7 @@ func (w *Wrapper) BalanceOf(id *owner.ID) (int64, error) { result, err := w.client.BalanceOf(args) if err != nil { - return 0, err + return nil, err } return result.Amount(), nil