2020-07-24 13:54:03 +00:00
|
|
|
package wrapper
|
|
|
|
|
2020-09-01 14:33:26 +00:00
|
|
|
import (
|
2020-10-28 13:01:29 +00:00
|
|
|
"math/big"
|
|
|
|
|
2021-11-10 07:08:33 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
2020-09-01 14:33:26 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/balance"
|
2021-11-10 07:08:33 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/owner"
|
2020-09-01 14:33:26 +00:00
|
|
|
)
|
2020-07-24 13:54:03 +00:00
|
|
|
|
|
|
|
// BalanceOf receives the amount of funds in the client's account
|
|
|
|
// through the Balance contract call, and returns it.
|
2020-10-28 13:01:29 +00:00
|
|
|
func (w *Wrapper) BalanceOf(id *owner.ID) (*big.Int, error) {
|
2021-11-10 07:08:33 +00:00
|
|
|
h, err := address.StringToUint160(id.String())
|
2020-09-01 14:33:26 +00:00
|
|
|
if err != nil {
|
2020-10-28 13:01:29 +00:00
|
|
|
return nil, err
|
2020-09-01 14:33:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
args := balance.GetBalanceOfArgs{}
|
2021-11-10 07:08:33 +00:00
|
|
|
args.SetWallet(h.BytesBE())
|
2020-09-01 14:33:26 +00:00
|
|
|
|
|
|
|
result, err := w.client.BalanceOf(args)
|
|
|
|
if err != nil {
|
2020-10-28 13:01:29 +00:00
|
|
|
return nil, err
|
2020-09-01 14:33:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result.Amount(), nil
|
2020-07-24 13:54:03 +00:00
|
|
|
}
|