[#834] neofs-adm: Update NNS contract during contract update

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-09-21 15:21:38 +03:00 committed by Alex Vanin
parent d996004d80
commit ce8a906bb5
3 changed files with 17 additions and 5 deletions

View file

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

View file

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

View file

@ -17,5 +17,5 @@ func updateContracts(cmd *cobra.Command, _ []string) error {
return err
}
return wCtx.setNNS()
return wCtx.deployNNS("update")
}