[#83] policy: Allow to update contract

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
pull/83/head
Evgenii Stratonikov 2024-03-14 09:58:25 +03:00
parent 5119f655fe
commit e27b8ad306
2 changed files with 16 additions and 0 deletions

View File

@ -1,4 +1,6 @@
name: "APE"
permissions:
- methods: ["update"]
safemethods:
- "getAdmin"
- "listChains"

View File

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