From f9d9f3346127e17f0c14124d0a9fff16130379a0 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 11 Aug 2021 11:48:01 +0300 Subject: [PATCH] neofs-adm: use `nnsResolveHash` instead of custom code Signed-off-by: Evgenii Stratonikov --- cmd/neofs-adm/internal/modules/morph/dump.go | 20 ++---------------- cmd/neofs-adm/internal/modules/morph/epoch.go | 21 ++----------------- 2 files changed, 4 insertions(+), 37 deletions(-) diff --git a/cmd/neofs-adm/internal/modules/morph/dump.go b/cmd/neofs-adm/internal/modules/morph/dump.go index 4b98ef27..f48a5fe7 100644 --- a/cmd/neofs-adm/internal/modules/morph/dump.go +++ b/cmd/neofs-adm/internal/modules/morph/dump.go @@ -13,7 +13,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" - "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm" "github.com/nspcc-dev/neo-go/pkg/vm/emit" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" @@ -113,27 +112,12 @@ func dumpNetworkConfig(cmd *cobra.Command, _ []string) error { return fmt.Errorf("can't get NNS contract info: %w", err) } - res, err := wCtx.Client.InvokeFunction(cs.Hash, "resolve", []smartcontract.Parameter{ - {Type: smartcontract.StringType, Value: netmapContract + ".neofs"}, - {Type: smartcontract.IntegerType, Value: int64(nns.TXT)}, - }, nil) + nmHash, err := nnsResolveHash(wCtx.Client, cs.Hash, netmapContract+".neofs") if err != nil { return fmt.Errorf("can't get netmap contract hash: %w", err) } - if len(res.Stack) == 0 { - return errors.New("empty response from NNS") - } - var nmHash util.Uint160 - bs, err := res.Stack[0].TryBytes() - if err == nil { - nmHash, err = util.Uint160DecodeStringLE(string(bs)) - } - if err != nil { - return fmt.Errorf("invalid response from NNS contract: %w", err) - } - - res, err = wCtx.Client.InvokeFunction(nmHash, "listConfig", + res, err := wCtx.Client.InvokeFunction(nmHash, "listConfig", []smartcontract.Parameter{}, []transaction.Signer{{}}) if err != nil || res.State != vm.HaltState.String() || len(res.Stack) == 0 { return errors.New("can't fetch list of network config keys from the netmap contract") diff --git a/cmd/neofs-adm/internal/modules/morph/epoch.go b/cmd/neofs-adm/internal/modules/morph/epoch.go index 2fcb4323..9c7121e5 100644 --- a/cmd/neofs-adm/internal/modules/morph/epoch.go +++ b/cmd/neofs-adm/internal/modules/morph/epoch.go @@ -4,12 +4,10 @@ import ( "errors" "fmt" - nns "github.com/nspcc-dev/neo-go/examples/nft-nd-nns" "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" - "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm" "github.com/nspcc-dev/neo-go/pkg/vm/emit" "github.com/spf13/cobra" @@ -27,27 +25,12 @@ func forceNewEpochCmd(cmd *cobra.Command, args []string) error { return fmt.Errorf("can't get NNS contract info: %w", err) } - res, err := wCtx.Client.InvokeFunction(cs.Hash, "resolve", []smartcontract.Parameter{ - {Type: smartcontract.StringType, Value: netmapContract + ".neofs"}, - {Type: smartcontract.IntegerType, Value: int64(nns.TXT)}, - }, nil) + nmHash, err := nnsResolveHash(wCtx.Client, cs.Hash, netmapContract+".neofs") if err != nil { return fmt.Errorf("can't get netmap contract hash: %w", err) } - if len(res.Stack) == 0 { - return errors.New("empty response from NNS") - } - var nmHash util.Uint160 - bs, err := res.Stack[0].TryBytes() - if err == nil { - nmHash, err = util.Uint160DecodeStringLE(string(bs)) - } - if err != nil { - return fmt.Errorf("invalid response from NNS contract: %w", err) - } - - res, err = wCtx.Client.InvokeFunction(nmHash, "epoch", []smartcontract.Parameter{}, []transaction.Signer{{ + res, err := wCtx.Client.InvokeFunction(nmHash, "epoch", []smartcontract.Parameter{}, []transaction.Signer{{ Account: wCtx.CommitteeAcc.Contract.ScriptHash(), Scopes: transaction.Global, // Scope is important, as we have nested call to container contract. }})