Skip to content

Commit

Permalink
*: Remove balance logic from pool
Browse files Browse the repository at this point in the history
Signed-off-by: Evgenii Baidakov <[email protected]>
  • Loading branch information
smallhive committed Oct 19, 2023
1 parent 915f859 commit 70329d7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 40 deletions.
30 changes: 21 additions & 9 deletions pkg/morphchain/balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ 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"
)

type (
BalanceFetcher struct {
cli *pool.Pool
gas util.Uint160
notary util.Uint160
cli *pool.Pool
}

BalanceFetcherArgs struct {
Expand All @@ -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
}

Expand All @@ -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
}
31 changes: 0 additions & 31 deletions pkg/pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 70329d7

Please sign in to comment.