From ce8a906bb5b3225f06a99611570d37b213000b30 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Tue, 21 Sep 2021 15:21:38 +0300 Subject: [PATCH] [#834] neofs-adm: Update NNS contract during contract update Signed-off-by: Alex Vanin --- .../internal/modules/morph/initialize.go | 2 +- .../modules/morph/initialize_deploy.go | 18 +++++++++++++++--- cmd/neofs-adm/internal/modules/morph/update.go | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/cmd/neofs-adm/internal/modules/morph/initialize.go b/cmd/neofs-adm/internal/modules/morph/initialize.go index 6f29122800..1ca762ff87 100644 --- a/cmd/neofs-adm/internal/modules/morph/initialize.go +++ b/cmd/neofs-adm/internal/modules/morph/initialize.go @@ -57,7 +57,7 @@ func initializeSideChainCmd(cmd *cobra.Command, args []string) error { // 3. Deploy NNS contract. cmd.Println("Stage 3: deploy NNS contract.") - if err := initCtx.deployNNS(); err != nil { + if err := initCtx.deployNNS("deploy"); err != nil { return err } diff --git a/cmd/neofs-adm/internal/modules/morph/initialize_deploy.go b/cmd/neofs-adm/internal/modules/morph/initialize_deploy.go index 00e8a2190e..f5fa2d0048 100644 --- a/cmd/neofs-adm/internal/modules/morph/initialize_deploy.go +++ b/cmd/neofs-adm/internal/modules/morph/initialize_deploy.go @@ -66,25 +66,37 @@ type contractState struct { Hash util.Uint160 } -func (c *initializeContext) deployNNS() error { +func (c *initializeContext) deployNNS(method string) error { cs, err := c.readContract(nnsContract) if err != nil { return err } h := state.CreateContractHash(c.CommitteeAcc.Contract.ScriptHash(), cs.NEF.Checksum, cs.Manifest.Name) - if _, err := c.Client.GetContractStateByHash(h); err == nil { + if _, err := c.Client.GetContractStateByHash(h); err == nil && method != "update" { return nil } params := getContractDeployParameters(cs.RawNEF, cs.RawManifest, nil) + if method == "update" { + params = params[:len(params)-1] // update has only NEF and manifest args + } + signer := transaction.Signer{ Account: c.CommitteeAcc.Contract.ScriptHash(), Scopes: transaction.CalledByEntry, } mgmtHash := c.nativeHash(nativenames.Management) - res, err := c.Client.InvokeFunction(mgmtHash, "deploy", params, []transaction.Signer{signer}) + if method == "update" { + nnsCs, err := c.Client.GetContractStateByID(1) + if err != nil { + return fmt.Errorf("can't resolve NNS hash for contract update: %w", err) + } + mgmtHash = nnsCs.Hash + } + + res, err := c.Client.InvokeFunction(mgmtHash, method, params, []transaction.Signer{signer}) if err != nil { return fmt.Errorf("can't deploy NNS contract: %w", err) } diff --git a/cmd/neofs-adm/internal/modules/morph/update.go b/cmd/neofs-adm/internal/modules/morph/update.go index ad17544cf7..86c01e7b2c 100644 --- a/cmd/neofs-adm/internal/modules/morph/update.go +++ b/cmd/neofs-adm/internal/modules/morph/update.go @@ -17,5 +17,5 @@ func updateContracts(cmd *cobra.Command, _ []string) error { return err } - return wCtx.setNNS() + return wCtx.deployNNS("update") }