neofs-adm: use `nnsResolveHash` instead of custom code

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
remotes/fyrchik/meta-pebble
Evgenii Stratonikov 2021-08-11 11:48:01 +03:00 committed by Alex Vanin
parent 72b8d919fe
commit f9d9f33461
2 changed files with 4 additions and 37 deletions

View File

@ -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")

View File

@ -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.
}})