From 4368243bed365983e992a71c14fcdc08fe4cff4d Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 24 Oct 2023 13:13:49 +0300 Subject: [PATCH] [#750] adm: Drop deprecated NEP17BalanceOf() Signed-off-by: Evgenii Stratonikov --- .../modules/morph/initialize_register.go | 7 +++++-- .../modules/morph/initialize_transfer.go | 12 ++++++++---- .../internal/modules/morph/local_client.go | 17 ----------------- .../internal/modules/morph/n3client.go | 1 - 4 files changed, 13 insertions(+), 24 deletions(-) diff --git a/cmd/frostfs-adm/internal/modules/morph/initialize_register.go b/cmd/frostfs-adm/internal/modules/morph/initialize_register.go index 469b269de..60bb7f8ed 100644 --- a/cmd/frostfs-adm/internal/modules/morph/initialize_register.go +++ b/cmd/frostfs-adm/internal/modules/morph/initialize_register.go @@ -3,6 +3,7 @@ package morph import ( "errors" "fmt" + "math/big" "github.com/nspcc-dev/neo-go/pkg/core/native" "github.com/nspcc-dev/neo-go/pkg/core/state" @@ -11,6 +12,7 @@ import ( "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/neo" + "github.com/nspcc-dev/neo-go/pkg/rpcclient/nep17" "github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap" "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" "github.com/nspcc-dev/neo-go/pkg/util" @@ -134,8 +136,9 @@ func (c *initializeContext) transferNEOToAlphabetContracts() error { } func (c *initializeContext) transferNEOFinished(neoHash util.Uint160) (bool, error) { - bal, err := c.Client.NEP17BalanceOf(neoHash, c.CommitteeAcc.Contract.ScriptHash()) - return bal < native.NEOTotalSupply, err + r := nep17.NewReader(c.ReadOnlyInvoker, neoHash) + bal, err := r.BalanceOf(c.CommitteeAcc.Contract.ScriptHash()) + return bal.Cmp(big.NewInt(native.NEOTotalSupply)) == -1, err } var errGetPriceInvalid = errors.New("`getRegisterPrice`: invalid response") diff --git a/cmd/frostfs-adm/internal/modules/morph/initialize_transfer.go b/cmd/frostfs-adm/internal/modules/morph/initialize_transfer.go index b032780be..45db6489f 100644 --- a/cmd/frostfs-adm/internal/modules/morph/initialize_transfer.go +++ b/cmd/frostfs-adm/internal/modules/morph/initialize_transfer.go @@ -2,6 +2,7 @@ package morph import ( "fmt" + "math/big" "github.com/nspcc-dev/neo-go/pkg/core/native" "github.com/nspcc-dev/neo-go/pkg/core/transaction" @@ -9,6 +10,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/rpcclient" "github.com/nspcc-dev/neo-go/pkg/rpcclient/gas" "github.com/nspcc-dev/neo-go/pkg/rpcclient/neo" + "github.com/nspcc-dev/neo-go/pkg/rpcclient/nep17" "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" scContext "github.com/nspcc-dev/neo-go/pkg/smartcontract/context" "github.com/nspcc-dev/neo-go/pkg/vm/emit" @@ -80,8 +82,9 @@ func (c *initializeContext) transferFunds() error { func (c *initializeContext) transferFundsFinished() (bool, error) { acc := c.Accounts[0] - res, err := c.Client.NEP17BalanceOf(gas.Hash, acc.Contract.ScriptHash()) - return res > initialAlphabetGASAmount/2, err + r := nep17.NewReader(c.ReadOnlyInvoker, gas.Hash) + res, err := r.BalanceOf(acc.Contract.ScriptHash()) + return res.Cmp(big.NewInt(initialAlphabetGASAmount/2)) == 1, err } func (c *initializeContext) multiSignAndSend(tx *transaction.Transaction, accType string) error { @@ -147,8 +150,9 @@ func (c *initializeContext) multiSign(tx *transaction.Transaction, accType strin func (c *initializeContext) transferGASToProxy() error { proxyCs := c.getContract(proxyContract) - bal, err := c.Client.NEP17BalanceOf(gas.Hash, proxyCs.Hash) - if err != nil || bal > 0 { + r := nep17.NewReader(c.ReadOnlyInvoker, gas.Hash) + bal, err := r.BalanceOf(proxyCs.Hash) + if err != nil || bal.Sign() > 0 { return err } diff --git a/cmd/frostfs-adm/internal/modules/morph/local_client.go b/cmd/frostfs-adm/internal/modules/morph/local_client.go index cd094ca29..2ef8774bb 100644 --- a/cmd/frostfs-adm/internal/modules/morph/local_client.go +++ b/cmd/frostfs-adm/internal/modules/morph/local_client.go @@ -35,7 +35,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/vm/emit" "github.com/nspcc-dev/neo-go/pkg/vm/opcode" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" - "github.com/nspcc-dev/neo-go/pkg/vm/vmstate" "github.com/nspcc-dev/neo-go/pkg/wallet" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -324,22 +323,6 @@ func getSigners(sender *wallet.Account, cosigners []rpcclient.SignerAccount) ([] return signers, accounts, nil } -func (l *localClient) NEP17BalanceOf(h util.Uint160, acc util.Uint160) (int64, error) { - res, err := invokeFunction(l, h, "balanceOf", []any{acc}, nil) - if err != nil { - return 0, err - } - if res.State != vmstate.Halt.String() || len(res.Stack) == 0 { - return 0, fmt.Errorf("`balance`: invalid response (empty: %t): %s", - len(res.Stack) == 0, res.FaultException) - } - bi, err := res.Stack[0].TryInteger() - if err != nil || !bi.IsInt64() { - return 0, fmt.Errorf("`balance`: invalid response") - } - return bi.Int64(), nil -} - func (l *localClient) InvokeScript(script []byte, signers []transaction.Signer) (*result.Invoke, error) { lastBlock, err := l.bc.GetBlock(l.bc.CurrentBlockHash()) if err != nil { diff --git a/cmd/frostfs-adm/internal/modules/morph/n3client.go b/cmd/frostfs-adm/internal/modules/morph/n3client.go index 7ba5a7ce3..ac9abee8c 100644 --- a/cmd/frostfs-adm/internal/modules/morph/n3client.go +++ b/cmd/frostfs-adm/internal/modules/morph/n3client.go @@ -32,7 +32,6 @@ type Client interface { GetApplicationLog(util.Uint256, *trigger.Type) (*result.ApplicationLog, error) GetVersion() (*result.Version, error) CreateTxFromScript([]byte, *wallet.Account, int64, int64, []rpcclient.SignerAccount) (*transaction.Transaction, error) - NEP17BalanceOf(util.Uint160, util.Uint160) (int64, error) SendRawTransaction(*transaction.Transaction) (util.Uint256, error) GetCommittee() (keys.PublicKeys, error) CalculateNotaryFee(uint8) (int64, error)