From e27b8ad3067dc8db9e7f18b753ee18bfb3d41091 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Thu, 14 Mar 2024 09:58:25 +0300 Subject: [PATCH] [#83] policy: Allow to update contract Signed-off-by: Evgenii Stratonikov --- policy/config.yml | 2 ++ policy/policy_contract.go | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/policy/config.yml b/policy/config.yml index e0c28af..4e1163b 100644 --- a/policy/config.yml +++ b/policy/config.yml @@ -1,4 +1,6 @@ name: "APE" +permissions: + - methods: ["update"] safemethods: - "getAdmin" - "listChains" diff --git a/policy/policy_contract.go b/policy/policy_contract.go index a199ebd..1e5b7bd 100644 --- a/policy/policy_contract.go +++ b/policy/policy_contract.go @@ -4,6 +4,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-contract/common" "github.com/nspcc-dev/neo-go/pkg/interop" "github.com/nspcc-dev/neo-go/pkg/interop/iterator" + "github.com/nspcc-dev/neo-go/pkg/interop/native/management" "github.com/nspcc-dev/neo-go/pkg/interop/runtime" "github.com/nspcc-dev/neo-go/pkg/interop/storage" ) @@ -36,6 +37,8 @@ const ( // _deploy function sets up initial list of inner ring public keys. func _deploy(data any, isUpdate bool) { if isUpdate { + args := data.([]any) + common.CheckVersion(args[len(args)-1].(int)) return } @@ -69,6 +72,17 @@ func Version() int { return common.Version } +// Update method updates contract source code and manifest. It can be invoked +// by committee only. +func Update(script []byte, manifest []byte, data any) { + if !common.HasUpdateAccess() { + panic("only committee can update contract") + } + + management.UpdateWithData(script, manifest, common.AppendVersion(data)) + runtime.Log("policy contract updated") +} + func SetAdmin(addr interop.Hash160) { common.CheckAlphabetWitness()