frostfs-contract/common/update.go
Alex Vanin 88c738b736 [#49] Support contract migration
At initialization contract saves master script hash
that allows to re-initialize or migrate contract.

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
2021-02-12 18:33:55 +03:00

22 lines
549 B
Go

package common
import (
"github.com/nspcc-dev/neo-go/pkg/interop"
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
)
const OwnerKey = "contractOwner"
// HasUpdateAccess returns true if contract can be initialized, re-initialized
// or migrated.
func HasUpdateAccess(ctx storage.Context) bool {
data := storage.Get(ctx, OwnerKey)
if data == nil { // contract has not been initialized yet, return true
return true
}
owner := data.(interop.Hash160)
return runtime.CheckWitness(owner)
}