diff --git a/cmd/neofs-adm/internal/modules/morph/balance.go b/cmd/neofs-adm/internal/modules/morph/balance.go index d620eca91e..1566e6bd1a 100644 --- a/cmd/neofs-adm/internal/modules/morph/balance.go +++ b/cmd/neofs-adm/internal/modules/morph/balance.go @@ -7,7 +7,6 @@ import ( "math/big" "github.com/nspcc-dev/neo-go/pkg/core/native/noderoles" - "github.com/nspcc-dev/neo-go/pkg/core/state" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/encoding/address" "github.com/nspcc-dev/neo-go/pkg/encoding/fixedn" @@ -19,7 +18,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neo-go/pkg/vm/vmstate" - "github.com/nspcc-dev/neofs-contract/nns" + "github.com/nspcc-dev/neofs-contract/rpc/nns" "github.com/nspcc-dev/neofs-sdk-go/netmap" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -42,7 +41,7 @@ func dumpBalances(cmd *cobra.Command, _ []string) error { dumpStorage, _ = cmd.Flags().GetBool(dumpBalancesStorageFlag) dumpAlphabet, _ = cmd.Flags().GetBool(dumpBalancesAlphabetFlag) dumpProxy, _ = cmd.Flags().GetBool(dumpBalancesProxyFlag) - nnsCs *state.Contract + nnsReader *nns.ContractReader nmHash util.Uint160 ) @@ -54,12 +53,13 @@ func dumpBalances(cmd *cobra.Command, _ []string) error { inv := invoker.New(c, nil) if dumpStorage || dumpAlphabet || dumpProxy { - nnsCs, err = c.GetContractStateByID(1) + nnsHash, err := nns.InferHash(c) if err != nil { - return fmt.Errorf("can't get NNS contract info: %w", err) + return fmt.Errorf("can't get NNS contract hash: %w", err) } + nnsReader = nns.NewReader(inv, nnsHash) - nmHash, err = nnsResolveHash(inv, nnsCs.Hash, netmapContract+".neofs") + nmHash, err = nnsReader.ResolveFSContract(nns.NameNetmap) if err != nil { return fmt.Errorf("can't get netmap contract hash: %w", err) } @@ -109,7 +109,7 @@ func dumpBalances(cmd *cobra.Command, _ []string) error { } if dumpProxy { - h, err := nnsResolveHash(inv, nnsCs.Hash, proxyContract+".neofs") + h, err := nnsReader.ResolveFSContract(nns.NameProxy) if err != nil { return fmt.Errorf("can't get hash of the proxy contract: %w", err) } @@ -124,23 +124,8 @@ func dumpBalances(cmd *cobra.Command, _ []string) error { if dumpAlphabet { alphaList := make([]accBalancePair, len(irList)) - b := smartcontract.NewBuilder() for i := range alphaList { - b.InvokeMethod(nnsCs.Hash, "resolve", getAlphabetNNSDomain(i), int64(nns.TXT)) - } - - script, err := b.Script() - if err != nil { - return fmt.Errorf("resolving alphabet hashes script: %w", err) - } - - alphaRes, err := c.InvokeScript(script, nil) - if err != nil { - return fmt.Errorf("can't fetch info from NNS: %w", err) - } - - for i := range alphaList { - h, err := parseNNSResolveResult(alphaRes.Stack[i]) + h, err := nnsReader.ResolveFSContract(getAlphabetNNSDomain(i)) if err != nil { return fmt.Errorf("can't fetch the alphabet contract #%d hash: %w", i, err) } diff --git a/cmd/neofs-adm/internal/modules/morph/config.go b/cmd/neofs-adm/internal/modules/morph/config.go index f5b0c2bc0c..25222113ed 100644 --- a/cmd/neofs-adm/internal/modules/morph/config.go +++ b/cmd/neofs-adm/internal/modules/morph/config.go @@ -14,6 +14,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap" "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" + "github.com/nspcc-dev/neofs-contract/rpc/nns" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -28,12 +29,13 @@ func dumpNetworkConfig(cmd *cobra.Command, _ []string) error { inv := invoker.New(c, nil) - cs, err := c.GetContractStateByID(1) + nnsHash, err := nns.InferHash(c) if err != nil { - return fmt.Errorf("can't get NNS contract info: %w", err) + return fmt.Errorf("can't find NNS hash: %w", err) } + nnsReader := nns.NewReader(inv, nnsHash) - nmHash, err := nnsResolveHash(inv, cs.Hash, netmapContract+".neofs") + nmHash, err := nnsReader.ResolveFSContract(nns.NameNetmap) if err != nil { return fmt.Errorf("can't get netmap contract hash: %w", err) } @@ -102,12 +104,13 @@ func setConfigCmd(cmd *cobra.Command, args []string) error { return fmt.Errorf("can't initialize context: %w", err) } - cs, err := wCtx.Client.GetContractStateByID(1) + nnsHash, err := nns.InferHash(wCtx.Client) if err != nil { - return fmt.Errorf("can't get NNS contract info: %w", err) + return err } + nnsReader := nns.NewReader(wCtx.ReadOnlyInvoker, nnsHash) - nmHash, err := nnsResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, netmapContract+".neofs") + nmHash, err := nnsReader.ResolveFSContract(nns.NameNetmap) if err != nil { return fmt.Errorf("can't get netmap contract hash: %w", err) } diff --git a/cmd/neofs-adm/internal/modules/morph/container.go b/cmd/neofs-adm/internal/modules/morph/container.go index 0f159f2309..76a3a778f1 100644 --- a/cmd/neofs-adm/internal/modules/morph/container.go +++ b/cmd/neofs-adm/internal/modules/morph/container.go @@ -13,6 +13,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" + "github.com/nspcc-dev/neofs-contract/rpc/nns" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -27,13 +28,15 @@ func getContainerContractHash(cmd *cobra.Command, inv *invoker.Invoker, c Client ch, err = util.Uint160DecodeStringLE(s) } if err != nil { - nnsCs, err := c.GetContractStateByID(1) + nnsHash, err := nns.InferHash(c) if err != nil { - return util.Uint160{}, fmt.Errorf("can't get NNS contract state: %w", err) + return ch, fmt.Errorf("can't get NNS contract hash: %w", err) } - ch, err = nnsResolveHash(inv, nnsCs.Hash, containerContract+".neofs") + nnsReader := nns.NewReader(inv, nnsHash) + + ch, err = nnsReader.ResolveFSContract(nns.NameContainer) if err != nil { - return util.Uint160{}, err + return ch, fmt.Errorf("can't fetch container contract hash: %w", err) } } return ch, nil @@ -168,12 +171,13 @@ func restoreContainers(cmd *cobra.Command, _ []string) error { } defer wCtx.close() - nnsCs, err := wCtx.Client.GetContractStateByID(1) + nnsHash, err := nns.InferHash(wCtx.Client) if err != nil { - return fmt.Errorf("can't get NNS contract state: %w", err) + return fmt.Errorf("can't get NNS contract hash: %w", err) } + nnsReader := nns.NewReader(wCtx.ReadOnlyInvoker, nnsHash) - ch, err := nnsResolveHash(wCtx.ReadOnlyInvoker, nnsCs.Hash, containerContract+".neofs") + ch, err := nnsReader.ResolveFSContract(nns.NameContainer) if err != nil { return fmt.Errorf("can't fetch container contract hash: %w", err) } diff --git a/cmd/neofs-adm/internal/modules/morph/deploy.go b/cmd/neofs-adm/internal/modules/morph/deploy.go index 8f5e1eea6d..7967202d78 100644 --- a/cmd/neofs-adm/internal/modules/morph/deploy.go +++ b/cmd/neofs-adm/internal/modules/morph/deploy.go @@ -15,7 +15,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" "github.com/nspcc-dev/neo-go/pkg/vm/emit" "github.com/nspcc-dev/neo-go/pkg/vm/opcode" - "github.com/nspcc-dev/neofs-contract/nns" + "github.com/nspcc-dev/neofs-contract/rpc/nns" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -76,9 +76,9 @@ func deployContractCmd(cmd *cobra.Command, args []string) error { return err } - nnsCs, err := c.Client.GetContractStateByID(1) + nnsHash, err := nns.InferHash(c.Client) if err != nil { - return fmt.Errorf("can't fetch NNS contract state: %w", err) + return fmt.Errorf("can't fetch NNS contract hash: %w", err) } callHash := management.Hash @@ -87,7 +87,7 @@ func deployContractCmd(cmd *cobra.Command, args []string) error { domain := ctrName + "." + zone isUpdate, _ := cmd.Flags().GetBool(updateFlag) if isUpdate { - cs.Hash, err = nnsResolveHash(c.ReadOnlyInvoker, nnsCs.Hash, domain) + cs.Hash, err = nnsResolveHash(c.ReadOnlyInvoker, nnsHash, domain) if err != nil { return fmt.Errorf("can't fetch contract hash from NNS: %w", err) } @@ -113,28 +113,28 @@ func deployContractCmd(cmd *cobra.Command, args []string) error { if !isUpdate { bw := io.NewBufBinWriter() emit.Instruction(bw.BinWriter, opcode.INITSSLOT, []byte{1}) - emit.AppCall(bw.BinWriter, nnsCs.Hash, "getPrice", callflag.All) + emit.AppCall(bw.BinWriter, nnsHash, "getPrice", callflag.All) emit.Opcodes(bw.BinWriter, opcode.STSFLD0) - emit.AppCall(bw.BinWriter, nnsCs.Hash, "setPrice", callflag.All, 1) + emit.AppCall(bw.BinWriter, nnsHash, "setPrice", callflag.All, 1) start := bw.Len() needRecord := false - ok, err := c.nnsRootRegistered(nnsCs.Hash, zone) + ok, err := c.nnsRootRegistered(nnsHash, zone) if err != nil { return err } else if !ok { needRecord = true - emit.AppCall(bw.BinWriter, nnsCs.Hash, "registerTLD", callflag.All, + emit.AppCall(bw.BinWriter, nnsHash, "registerTLD", callflag.All, zone, "ops@nspcc.ru", int64(3600), int64(600), int64(defaultExpirationTime), int64(3600)) - emit.AppCall(bw.BinWriter, nnsCs.Hash, "register", callflag.All, + emit.AppCall(bw.BinWriter, nnsHash, "register", callflag.All, domain, c.CommitteeAcc.Contract.ScriptHash(), "ops@nspcc.ru", int64(3600), int64(600), int64(defaultExpirationTime), int64(3600)) emit.Opcodes(bw.BinWriter, opcode.ASSERT) } else { - s, ok, err := c.nnsRegisterDomainScript(nnsCs.Hash, cs.Hash, domain) + s, ok, err := c.nnsRegisterDomainScript(nnsHash, cs.Hash, domain) if err != nil { return err } @@ -144,9 +144,9 @@ func deployContractCmd(cmd *cobra.Command, args []string) error { } } if needRecord { - emit.AppCall(bw.BinWriter, nnsCs.Hash, "deleteRecords", callflag.All, domain, int64(nns.TXT)) - emit.AppCall(bw.BinWriter, nnsCs.Hash, "addRecord", callflag.All, - domain, int64(nns.TXT), address.Uint160ToString(cs.Hash)) + emit.AppCall(bw.BinWriter, nnsHash, "deleteRecords", callflag.All, domain, nns.TXT) + emit.AppCall(bw.BinWriter, nnsHash, "addRecord", callflag.All, + domain, nns.TXT, address.Uint160ToString(cs.Hash)) } if bw.Err != nil { @@ -154,7 +154,7 @@ func deployContractCmd(cmd *cobra.Command, args []string) error { } else if bw.Len() != start { w.WriteBytes(bw.Bytes()) emit.Opcodes(w.BinWriter, opcode.LDSFLD0, opcode.PUSH1, opcode.PACK) - emit.AppCallNoArgs(w.BinWriter, nnsCs.Hash, "setPrice", callflag.All) + emit.AppCallNoArgs(w.BinWriter, nnsHash, "setPrice", callflag.All) if needRecord { c.Command.Printf("NNS: Set %s -> %s\n", domain, cs.Hash.StringLE()) diff --git a/cmd/neofs-adm/internal/modules/morph/dump_hashes.go b/cmd/neofs-adm/internal/modules/morph/dump_hashes.go index bcf6eefaf5..de5c6ba7fe 100644 --- a/cmd/neofs-adm/internal/modules/morph/dump_hashes.go +++ b/cmd/neofs-adm/internal/modules/morph/dump_hashes.go @@ -19,7 +19,7 @@ import ( "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/neofs-contract/nns" + "github.com/nspcc-dev/neofs-contract/rpc/nns" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -39,21 +39,23 @@ func dumpContractHashes(cmd *cobra.Command, _ []string) error { return fmt.Errorf("can't create N3 client: %w", err) } - cs, err := c.GetContractStateByID(1) + inv := invoker.New(c, nil) + nnsHash, err := nns.InferHash(c) if err != nil { - return err + return fmt.Errorf("can't get NNS contract hash: %w", err) } + nnsReader := nns.NewReader(inv, nnsHash) zone, _ := cmd.Flags().GetString(customZoneFlag) if zone != "" { - return dumpCustomZoneHashes(cmd, cs.Hash, zone, c) + return dumpCustomZoneHashes(cmd, nnsHash, zone, c) } - infos := []contractDumpInfo{{name: nnsContract, hash: cs.Hash}} + infos := []contractDumpInfo{{name: nnsContract, hash: nnsHash}} irSize := 0 for ; irSize < lastGlagoliticLetter; irSize++ { - ok, err := nnsIsAvailable(c, cs.Hash, getAlphabetNNSDomain(irSize)) + ok, err := nnsReader.IsAvailable(getAlphabetNNSDomain(irSize) + "." + nns.ContractTLD) if err != nil { return err } else if ok { @@ -61,54 +63,17 @@ func dumpContractHashes(cmd *cobra.Command, _ []string) error { } } - b := smartcontract.NewBuilder() - - if irSize != 0 { - b.Reset() - for i := 0; i < irSize; i++ { - b.InvokeMethod(cs.Hash, "resolve", getAlphabetNNSDomain(i), int64(nns.TXT)) - } - - script, err := b.Script() - if err != nil { - return fmt.Errorf("resolving alphabet hashes script: %w", err) - } - - alphaRes, err := c.InvokeScript(script, nil) - if err != nil { - return fmt.Errorf("can't fetch info from NNS: %w", err) - } - - for i := 0; i < irSize; i++ { - info := contractDumpInfo{name: fmt.Sprintf("alphabet %d", i)} - if h, err := parseNNSResolveResult(alphaRes.Stack[i]); err == nil { - info.hash = h - } - infos = append(infos, info) - } + var contracts = make([]string, 0, irSize+len(contractList)) + for i := 0; i < irSize; i++ { + contracts = append(contracts, getAlphabetNNSDomain(i)) } for _, ctrName := range contractList { - b.Reset() - b.InvokeMethod(cs.Hash, "resolve", ctrName+".neofs", int64(nns.TXT)) - - script, err := b.Script() + h, err := nnsReader.ResolveFSContract(ctrName) if err != nil { - return fmt.Errorf("resolving neofs contract hashes script: %w", err) - } - - res, err := c.InvokeScript(script, nil) - if err != nil { - return fmt.Errorf("can't fetch info from NNS: %w", err) - } - - info := contractDumpInfo{name: ctrName} - if len(res.Stack) != 0 { - if h, err := parseNNSResolveResult(res.Stack[0]); err == nil { - info.hash = h - } + return fmt.Errorf("can't resolve %s contract: %w", ctrName, err) } - infos = append(infos, info) + infos = append(infos, contractDumpInfo{name: ctrName, hash: h}) } fillContractVersion(cmd, c, infos) diff --git a/cmd/neofs-adm/internal/modules/morph/dump_names.go b/cmd/neofs-adm/internal/modules/morph/dump_names.go index 3f1b015a39..e6be50cf07 100644 --- a/cmd/neofs-adm/internal/modules/morph/dump_names.go +++ b/cmd/neofs-adm/internal/modules/morph/dump_names.go @@ -9,7 +9,7 @@ import ( "time" "github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker" - "github.com/nspcc-dev/neo-go/pkg/rpcclient/nep11" + "github.com/nspcc-dev/neofs-contract/rpc/nns" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -28,12 +28,12 @@ func dumpNames(cmd *cobra.Command, _ []string) error { if err != nil { return fmt.Errorf("can't create N3 client: %w", err) } - cs, err := c.GetContractStateByID(1) // NNS. + nnsHash, err := nns.InferHash(c) if err != nil { return err } - var n11r = nep11.NewNonDivisibleReader(invoker.New(c, nil), cs.Hash) - tokIter, err := n11r.Tokens() + var nnsReader = nns.NewReader(invoker.New(c, nil), nnsHash) + tokIter, err := nnsReader.Tokens() if err != nil { return err } @@ -48,7 +48,7 @@ func dumpNames(cmd *cobra.Command, _ []string) error { if zone != "" && !strings.HasSuffix(name, "."+zone) { continue } - props, err := n11r.Properties(toks[i]) + props, err := nnsReader.Properties(toks[i]) if err != nil { cmd.PrintErrf("Error getting properties for %s: %v\n", name, err) continue diff --git a/cmd/neofs-adm/internal/modules/morph/epoch.go b/cmd/neofs-adm/internal/modules/morph/epoch.go index 8369dc692e..18b678a7ea 100644 --- a/cmd/neofs-adm/internal/modules/morph/epoch.go +++ b/cmd/neofs-adm/internal/modules/morph/epoch.go @@ -9,6 +9,7 @@ import ( "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/emit" + "github.com/nspcc-dev/neofs-contract/rpc/nns" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -19,12 +20,13 @@ func forceNewEpochCmd(cmd *cobra.Command, _ []string) error { return fmt.Errorf("can't to initialize context: %w", err) } - cs, err := wCtx.Client.GetContractStateByID(1) + nnsHash, err := nns.InferHash(wCtx.Client) if err != nil { - return fmt.Errorf("can't get NNS contract info: %w", err) + return fmt.Errorf("can't get NNS hash: %w", err) } + var nnsReader = nns.NewReader(wCtx.ReadOnlyInvoker, nnsHash) - nmHash, err := nnsResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, netmapContract+".neofs") + nmHash, err := nnsReader.ResolveFSContract(nns.NameNetmap) if err != nil { return fmt.Errorf("can't get netmap contract hash: %w", err) } diff --git a/cmd/neofs-adm/internal/modules/morph/estimation.go b/cmd/neofs-adm/internal/modules/morph/estimation.go index 665209bed7..a94951ee64 100644 --- a/cmd/neofs-adm/internal/modules/morph/estimation.go +++ b/cmd/neofs-adm/internal/modules/morph/estimation.go @@ -11,6 +11,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker" "github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" + "github.com/nspcc-dev/neofs-contract/rpc/nns" "github.com/nspcc-dev/neofs-node/pkg/morph/client/container" cid "github.com/nspcc-dev/neofs-sdk-go/container/id" "github.com/spf13/cobra" @@ -45,10 +46,11 @@ func estimationsFunc(cmd *cobra.Command, _ []string) error { inv := invoker.New(c, nil) - nnsState, err := c.GetContractStateByID(1) + nnsHash, err := nns.InferHash(c) if err != nil { - return err + return fmt.Errorf("can't get NNS hash: %w", err) } + var nnsReader = nns.NewReader(inv, nnsHash) epoch, err := cmd.Flags().GetInt64(estimationsEpochFlag) if err != nil { @@ -56,7 +58,7 @@ func estimationsFunc(cmd *cobra.Command, _ []string) error { } if epoch <= 0 { - netmapHash, err := nnsResolveHash(inv, nnsState.Hash, netmapContract+".neofs") + netmapHash, err := nnsReader.ResolveFSContract(nns.NameNetmap) if err != nil { return fmt.Errorf("netmap contract hash resolution: %w", err) } @@ -69,7 +71,7 @@ func estimationsFunc(cmd *cobra.Command, _ []string) error { epoch = epochFromContract + epoch // epoch is negative here } - cnrHash, err := nnsResolveHash(inv, nnsState.Hash, containerContract+".neofs") + cnrHash, err := nnsReader.ResolveFSContract(nns.NameContainer) if err != nil { return fmt.Errorf("container contract hash resolution: %w", err) } diff --git a/cmd/neofs-adm/internal/modules/morph/initialize.go b/cmd/neofs-adm/internal/modules/morph/initialize.go index 1cd02d90e8..f1bd496582 100644 --- a/cmd/neofs-adm/internal/modules/morph/initialize.go +++ b/cmd/neofs-adm/internal/modules/morph/initialize.go @@ -7,12 +7,12 @@ import ( "path/filepath" "time" - "github.com/nspcc-dev/neo-go/pkg/core/state" "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/rpcclient/actor" "github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker" "github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger" + "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm/vmstate" "github.com/nspcc-dev/neo-go/pkg/wallet" "github.com/nspcc-dev/neofs-contract/rpc/nns" @@ -24,7 +24,8 @@ import ( ) type cache struct { - nnsCs *state.Contract + nnsHash util.Uint160 + nnsContract *nns.ContractReader } type initializeContext struct { @@ -241,18 +242,16 @@ func (c *initializeContext) awaitTx() error { return c.clientContext.awaitTx(c.Command) } -func (c *initializeContext) nnsContractState() (*state.Contract, error) { - if c.nnsCs != nil { - return c.nnsCs, nil - } - - cs, err := c.Client.GetContractStateByID(1) - if err != nil { - return nil, err +func (c *initializeContext) nnsReader() (util.Uint160, *nns.ContractReader, error) { + if c.nnsContract == nil { + h, err := nns.InferHash(c.Client) + if err != nil { + return util.Uint160{}, nil, err + } + c.nnsHash = h + c.nnsContract = nns.NewReader(invoker.New(c.Client, nil), h) } - - c.nnsCs = cs - return cs, nil + return c.nnsHash, c.nnsContract, nil } func (c *initializeContext) getSigner(fancyScope bool, acc *wallet.Account) transaction.Signer { @@ -265,13 +264,11 @@ func (c *initializeContext) getSigner(fancyScope bool, acc *wallet.Account) tran return *signer } - nnsHash, err := nns.InferHash(c.Client) + nnsHash, nnsReader, err := c.nnsReader() if err != nil { return *signer } - var nnsReader = nns.NewReader(invoker.New(c.Client, nil), nnsHash) - balanceHash, err := nnsReader.ResolveFSContract(nns.NameBalance) if err != nil && c.Contracts[balanceContract] != nil { balanceHash = c.Contracts[balanceContract].Hash diff --git a/cmd/neofs-adm/internal/modules/morph/initialize_deploy.go b/cmd/neofs-adm/internal/modules/morph/initialize_deploy.go index 01a6709f76..08087e2184 100644 --- a/cmd/neofs-adm/internal/modules/morph/initialize_deploy.go +++ b/cmd/neofs-adm/internal/modules/morph/initialize_deploy.go @@ -98,7 +98,7 @@ const ( func (c *initializeContext) deployNNS(method string) error { cs := c.getContract(nnsContract) - nnsCs, err := c.nnsContractState() + nnsCs, err := c.Client.GetContractStateByID(nns.ID) if err == nil { if nnsCs.NEF.Checksum == cs.NEF.Checksum { if method == deployMethodName { @@ -140,11 +140,10 @@ func (c *initializeContext) deployNNS(method string) error { func (c *initializeContext) updateContracts() error { alphaCs := c.getContract(alphabetContract) - nnsCs, err := c.nnsContractState() + nnsHash, nnsReader, err := c.nnsReader() if err != nil { return err } - nnsHash := nnsCs.Hash w := io2.NewBufBinWriter() @@ -164,7 +163,7 @@ func (c *initializeContext) updateContracts() error { // alphabet contracts should be deployed by individual nodes to get different hashes. for i, acc := range c.Accounts { - ctrHash, err := nnsResolveHash(c.ReadOnlyInvoker, nnsHash, getAlphabetNNSDomain(i)) + ctrHash, err := nnsReader.ResolveFSContract(getAlphabetNNSDomain(i)) if err != nil { return fmt.Errorf("can't resolve hash for contract update: %w", err) } @@ -198,7 +197,7 @@ func (c *initializeContext) updateContracts() error { cs := c.getContract(ctrName) method := updateMethodName - ctrHash, err := nnsResolveHash(c.ReadOnlyInvoker, nnsHash, ctrName+".neofs") + ctrHash, err := nnsReader.ResolveFSContract(ctrName) if err != nil { if errors.Is(err, errMissingNNSRecord) { // if contract not found we deploy it instead of update @@ -487,7 +486,7 @@ func (c *initializeContext) getContractDeployData(ctrHash util.Uint160, ctrName case containerContract: // In case if NNS is updated multiple times, we can't calculate // it's actual hash based on local data, thus query chain. - nnsCs, err := c.Client.GetContractStateByID(1) + nnsHash, err := nns.InferHash(c.Client) if err != nil { panic("NNS is not yet deployed") } @@ -495,7 +494,7 @@ func (c *initializeContext) getContractDeployData(ctrHash util.Uint160, ctrName c.Contracts[netmapContract].Hash, c.Contracts[balanceContract].Hash, c.Contracts[neofsIDContract].Hash, - nnsCs.Hash, + nnsHash, "container") case neofsIDContract: items = append(items, diff --git a/cmd/neofs-adm/internal/modules/morph/initialize_nns.go b/cmd/neofs-adm/internal/modules/morph/initialize_nns.go index 4bd6cb7b67..d558b83794 100644 --- a/cmd/neofs-adm/internal/modules/morph/initialize_nns.go +++ b/cmd/neofs-adm/internal/modules/morph/initialize_nns.go @@ -11,7 +11,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/io" "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/nns" "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" @@ -19,32 +18,33 @@ import ( "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/neofs-contract/rpc/nns" ) const defaultExpirationTime = 10 * 365 * 24 * time.Hour / time.Second func (c *initializeContext) setNNS() error { - nnsCs, err := c.Client.GetContractStateByID(1) + nnsHash, err := nns.InferHash(c.Client) if err != nil { return err } - ok, err := c.nnsRootRegistered(nnsCs.Hash, "neofs") + ok, err := c.nnsRootRegistered(nnsHash, "neofs") if err != nil { return err } else if !ok { - version, err := unwrap.Int64(c.CommitteeAct.Call(nnsCs.Hash, "version")) + version, err := unwrap.Int64(c.CommitteeAct.Call(nnsHash, "version")) if err != nil { return err } bw := io.NewBufBinWriter() if version < 18_000 { // 0.18.0 - emit.AppCall(bw.BinWriter, nnsCs.Hash, "register", callflag.All, + emit.AppCall(bw.BinWriter, nnsHash, "register", callflag.All, "neofs", c.CommitteeAcc.Contract.ScriptHash(), "ops@nspcc.ru", int64(3600), int64(600), int64(defaultExpirationTime), int64(3600)) } else { - emit.AppCall(bw.BinWriter, nnsCs.Hash, "registerTLD", callflag.All, + emit.AppCall(bw.BinWriter, nnsHash, "registerTLD", callflag.All, "neofs", "ops@nspcc.ru", int64(3600), int64(600), int64(defaultExpirationTime), int64(3600)) } emit.Opcodes(bw.BinWriter, opcode.ASSERT) @@ -60,8 +60,8 @@ func (c *initializeContext) setNNS() error { for i, acc := range c.Accounts { alphaCs.Hash = state.CreateContractHash(acc.Contract.ScriptHash(), alphaCs.NEF.Checksum, alphaCs.Manifest.Name) - domain := getAlphabetNNSDomain(i) - if err := c.nnsRegisterDomain(nnsCs.Hash, alphaCs.Hash, domain); err != nil { + domain := getAlphabetNNSDomain(i) + "." + nns.ContractTLD + if err := c.nnsRegisterDomain(nnsHash, alphaCs.Hash, domain); err != nil { return err } c.Command.Printf("NNS: Set %s -> %s\n", domain, alphaCs.Hash.StringLE()) @@ -71,7 +71,7 @@ func (c *initializeContext) setNNS() error { cs := c.getContract(ctrName) domain := ctrName + ".neofs" - if err := c.nnsRegisterDomain(nnsCs.Hash, cs.Hash, domain); err != nil { + if err := c.nnsRegisterDomain(nnsHash, cs.Hash, domain); err != nil { return err } c.Command.Printf("NNS: Set %s -> %s\n", domain, cs.Hash.StringLE()) @@ -81,7 +81,7 @@ func (c *initializeContext) setNNS() error { } func getAlphabetNNSDomain(i int) string { - return alphabetContract + strconv.FormatUint(uint64(i), 10) + ".neofs" + return nns.NameAlphabetPrefix + strconv.FormatUint(uint64(i), 10) } // wrapRegisterScriptWithPrice wraps a given script with `getPrice`/`setPrice` calls for NNS. @@ -143,11 +143,11 @@ func (c *initializeContext) nnsRegisterDomain(nnsHash, expectedHash util.Uint160 emit.Instruction(w.BinWriter, opcode.INITSSLOT, []byte{1}) wrapRegisterScriptWithPrice(w, nnsHash, script) - emit.AppCall(w.BinWriter, nnsHash, "deleteRecords", callflag.All, domain, int64(nns.TXT)) + emit.AppCall(w.BinWriter, nnsHash, "deleteRecords", callflag.All, domain, nns.TXT) emit.AppCall(w.BinWriter, nnsHash, "addRecord", callflag.All, - domain, int64(nns.TXT), expectedHash.StringLE()) + domain, nns.TXT, expectedHash.StringLE()) emit.AppCall(w.BinWriter, nnsHash, "addRecord", callflag.All, - domain, int64(nns.TXT), address.Uint160ToString(expectedHash)) + domain, nns.TXT, address.Uint160ToString(expectedHash)) return c.sendCommitteeTx(w.Bytes(), true) } @@ -172,7 +172,7 @@ func nnsResolveHash(inv *invoker.Invoker, nnsHash util.Uint160, domain string) ( } func nnsResolve(inv *invoker.Invoker, nnsHash util.Uint160, domain string) (stackitem.Item, error) { - return unwrap.Item(inv.Call(nnsHash, "resolve", domain, int64(nns.TXT))) + return unwrap.Item(inv.Call(nnsHash, "resolve", domain, nns.TXT)) } // parseNNSResolveResult parses the result of resolving NNS record. diff --git a/cmd/neofs-adm/internal/modules/morph/netmap_candidates.go b/cmd/neofs-adm/internal/modules/morph/netmap_candidates.go index f3b1b4620a..523b47533a 100644 --- a/cmd/neofs-adm/internal/modules/morph/netmap_candidates.go +++ b/cmd/neofs-adm/internal/modules/morph/netmap_candidates.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker" + "github.com/nspcc-dev/neofs-contract/rpc/nns" "github.com/nspcc-dev/neofs-node/cmd/internal/cmdprinter" "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap" "github.com/spf13/cobra" @@ -18,12 +19,13 @@ func listNetmapCandidatesNodes(cmd *cobra.Command, _ []string) error { inv := invoker.New(c, nil) - nnsCs, err := c.GetContractStateByID(1) + nnsHash, err := nns.InferHash(c) if err != nil { - return fmt.Errorf("can't get NNS contract info: %w", err) + return fmt.Errorf("can't get NNS hash: %w", err) } + var nnsReader = nns.NewReader(inv, nnsHash) - nmHash, err := nnsResolveHash(inv, nnsCs.Hash, netmapContract+".neofs") + nmHash, err := nnsReader.ResolveFSContract(nns.NameNetmap) if err != nil { return fmt.Errorf("can't get netmap contract hash: %w", err) } diff --git a/cmd/neofs-adm/internal/modules/morph/remove_node.go b/cmd/neofs-adm/internal/modules/morph/remove_node.go index ff5b49d141..1e0217f1d8 100644 --- a/cmd/neofs-adm/internal/modules/morph/remove_node.go +++ b/cmd/neofs-adm/internal/modules/morph/remove_node.go @@ -9,6 +9,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" "github.com/nspcc-dev/neo-go/pkg/vm/emit" netmapcontract "github.com/nspcc-dev/neofs-contract/netmap" + "github.com/nspcc-dev/neofs-contract/rpc/nns" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -33,12 +34,13 @@ func removeNodesCmd(cmd *cobra.Command, args []string) error { } defer wCtx.close() - cs, err := wCtx.Client.GetContractStateByID(1) + nnsHash, err := nns.InferHash(wCtx.Client) if err != nil { - return fmt.Errorf("can't get NNS contract info: %w", err) + return fmt.Errorf("can't get NNS hash: %w", err) } + var nnsReader = nns.NewReader(wCtx.ReadOnlyInvoker, nnsHash) - nmHash, err := nnsResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, netmapContract+".neofs") + nmHash, err := nnsReader.ResolveFSContract(nns.NameNetmap) if err != nil { return fmt.Errorf("can't get netmap contract hash: %w", err) } diff --git a/cmd/neofs-adm/internal/modules/morph/renew_domain.go b/cmd/neofs-adm/internal/modules/morph/renew_domain.go index af7855434d..fe2f3e3fb1 100644 --- a/cmd/neofs-adm/internal/modules/morph/renew_domain.go +++ b/cmd/neofs-adm/internal/modules/morph/renew_domain.go @@ -5,9 +5,8 @@ import ( "fmt" "strings" - "github.com/nspcc-dev/neo-go/pkg/rpcclient/nep11" - "github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap" "github.com/nspcc-dev/neo-go/pkg/smartcontract" + "github.com/nspcc-dev/neofs-contract/rpc/nns" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -27,14 +26,14 @@ func renewDomain(cmd *cobra.Command, _ []string) error { return err } defer wCtx.close() - nns, err := wCtx.Client.GetContractStateByID(1) + nnsHash, err := nns.InferHash(wCtx.Client) if err != nil { return err } + nnsReader := nns.NewReader(wCtx.ReadOnlyInvoker, nnsHash) var domains = make([]string, 0, 1) if recursive { - var n11r = nep11.NewNonDivisibleReader(wCtx.ReadOnlyInvoker, nns.Hash) - tokIter, err := n11r.Tokens() + tokIter, err := nnsReader.Tokens() if err != nil { return err } @@ -48,7 +47,7 @@ func renewDomain(cmd *cobra.Command, _ []string) error { } } } else { - avail, err := unwrap.Bool(wCtx.ReadOnlyInvoker.Call(nns.Hash, "isAvailable")) + avail, err := nnsReader.IsAvailable(dom) if err == nil && avail { return errors.New("domain is not registered or expired") } @@ -57,7 +56,7 @@ func renewDomain(cmd *cobra.Command, _ []string) error { b := smartcontract.NewBuilder() for i := range domains { - b.InvokeMethod(nns.Hash, "renew", domains[i]) + b.InvokeMethod(nnsHash, "renew", domains[i]) script, err := b.Script() if err != nil {