[#834] neofs-adm: Update NNS contract during contract update
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
d996004d80
commit
ce8a906bb5
3 changed files with 17 additions and 5 deletions
|
@ -57,7 +57,7 @@ func initializeSideChainCmd(cmd *cobra.Command, args []string) error {
|
||||||
|
|
||||||
// 3. Deploy NNS contract.
|
// 3. Deploy NNS contract.
|
||||||
cmd.Println("Stage 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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,25 +66,37 @@ type contractState struct {
|
||||||
Hash util.Uint160
|
Hash util.Uint160
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *initializeContext) deployNNS() error {
|
func (c *initializeContext) deployNNS(method string) error {
|
||||||
cs, err := c.readContract(nnsContract)
|
cs, err := c.readContract(nnsContract)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
h := state.CreateContractHash(c.CommitteeAcc.Contract.ScriptHash(), cs.NEF.Checksum, cs.Manifest.Name)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
params := getContractDeployParameters(cs.RawNEF, cs.RawManifest, 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{
|
signer := transaction.Signer{
|
||||||
Account: c.CommitteeAcc.Contract.ScriptHash(),
|
Account: c.CommitteeAcc.Contract.ScriptHash(),
|
||||||
Scopes: transaction.CalledByEntry,
|
Scopes: transaction.CalledByEntry,
|
||||||
}
|
}
|
||||||
|
|
||||||
mgmtHash := c.nativeHash(nativenames.Management)
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("can't deploy NNS contract: %w", err)
|
return fmt.Errorf("can't deploy NNS contract: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,5 +17,5 @@ func updateContracts(cmd *cobra.Command, _ []string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return wCtx.setNNS()
|
return wCtx.deployNNS("update")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue