diff --git a/pkg/morphchain/balance.go b/pkg/morphchain/balance.go index d1ef15f..5e428f6 100644 --- a/pkg/morphchain/balance.go +++ b/pkg/morphchain/balance.go @@ -4,6 +4,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/crypto/hash" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/rpcclient/gas" + "github.com/nspcc-dev/neo-go/pkg/rpcclient/nep17" "github.com/nspcc-dev/neo-go/pkg/rpcclient/notary" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neofs-net-monitor/pkg/pool" @@ -11,9 +12,7 @@ import ( type ( BalanceFetcher struct { - cli *pool.Pool - gas util.Uint160 - notary util.Uint160 + cli *pool.Pool } BalanceFetcherArgs struct { @@ -23,9 +22,7 @@ type ( func NewBalanceFetcher(p BalanceFetcherArgs) (*BalanceFetcher, error) { return &BalanceFetcher{ - cli: p.Cli, - gas: gas.Hash, - notary: notary.Hash, + cli: p.Cli, }, nil } @@ -42,13 +39,28 @@ func (b BalanceFetcher) FetchNotary(key keys.PublicKey) (int64, error) { } func (b BalanceFetcher) FetchGASByScriptHash(sh util.Uint160) (int64, error) { - return b.cli.NEP17BalanceOf(b.gas, sh) + res, err := gas.NewReader(b.cli).BalanceOf(sh) + if err != nil { + return 0, err + } + + return res.Int64(), nil } func (b BalanceFetcher) FetchNotaryByScriptHash(sh util.Uint160) (int64, error) { - return b.cli.NEP17BalanceOf(b.notary, sh) + res, err := notary.NewReader(b.cli).BalanceOf(sh) + if err != nil { + return 0, err + } + + return res.Int64(), nil } func (b BalanceFetcher) FetchNEP17TotalSupply(tokenHash util.Uint160) (int64, error) { - return b.cli.NEP17TotalSupply(tokenHash) + res, err := nep17.NewReader(b.cli, tokenHash).TotalSupply() + if err != nil { + return 0, err + } + + return res.Int64(), nil } diff --git a/pkg/pool/pool.go b/pkg/pool/pool.go index 023cac0..b3f6ca9 100644 --- a/pkg/pool/pool.go +++ b/pkg/pool/pool.go @@ -15,7 +15,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/neorpc/result" "github.com/nspcc-dev/neo-go/pkg/rpcclient" "github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker" - "github.com/nspcc-dev/neo-go/pkg/rpcclient/nep17" "github.com/nspcc-dev/neo-go/pkg/rpcclient/rolemgmt" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" @@ -122,36 +121,6 @@ func (p *Pool) GetContractStateByID(id int32) (*state.Contract, error) { return conn.GetContractStateByID(id) } -// NEP17BalanceOf invokes `balanceOf` NEP17 method on a specified contract. -func (p *Pool) NEP17BalanceOf(tokenHash, acc util.Uint160) (int64, error) { - invokerConn, err := p.NextInvoker() - if err != nil { - return 0, err - } - - res, err := nep17.NewReader(invokerConn, tokenHash).BalanceOf(acc) - if err != nil { - return 0, err - } - - return res.Int64(), nil -} - -// NEP17TotalSupply invokes `totalSupply` NEP17 method on a specified contract. -func (p *Pool) NEP17TotalSupply(tokenHash util.Uint160) (int64, error) { - invokerConn, err := p.NextInvoker() - if err != nil { - return 0, err - } - - res, err := nep17.NewReader(invokerConn, tokenHash).TotalSupply() - if err != nil { - return 0, err - } - - return res.Int64(), nil -} - // Call returns the results after calling the smart contract scripthash // with the given operation and parameters. // NOTE: this is test invoke and will not affect the blockchain.