[#204] *: check contract version during update

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2021-12-27 11:49:30 +03:00 committed by Alex Vanin
parent 8226bd4e43
commit 74cc2d0aea
12 changed files with 29 additions and 2 deletions

View file

@ -35,6 +35,8 @@ func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) {
func _deploy(data interface{}, isUpdate bool) { func _deploy(data interface{}, isUpdate bool) {
ctx := storage.GetContext() ctx := storage.GetContext()
if isUpdate { if isUpdate {
args := data.([]interface{})
common.CheckVersion(args[len(args)-1].(int))
storage.Delete(ctx, common.LegacyOwnerKey) storage.Delete(ctx, common.LegacyOwnerKey)
return return
} }

View file

@ -45,6 +45,8 @@ const (
func _deploy(data interface{}, isUpdate bool) { func _deploy(data interface{}, isUpdate bool) {
ctx := storage.GetContext() ctx := storage.GetContext()
if isUpdate { if isUpdate {
args := data.([]interface{})
common.CheckVersion(args[len(args)-1].(int))
storage.Delete(ctx, common.LegacyOwnerKey) storage.Delete(ctx, common.LegacyOwnerKey)
return return
} }

View file

@ -61,6 +61,8 @@ func init() {
func _deploy(data interface{}, isUpdate bool) { func _deploy(data interface{}, isUpdate bool) {
ctx := storage.GetContext() ctx := storage.GetContext()
if isUpdate { if isUpdate {
args := data.([]interface{})
common.CheckVersion(args[len(args)-1].(int))
storage.Delete(ctx, common.LegacyOwnerKey) storage.Delete(ctx, common.LegacyOwnerKey)
return return
} }

View file

@ -84,6 +84,8 @@ func OnNEP11Payment(a interop.Hash160, b int, c []byte, d interface{}) {
func _deploy(data interface{}, isUpdate bool) { func _deploy(data interface{}, isUpdate bool) {
ctx := storage.GetContext() ctx := storage.GetContext()
if isUpdate { if isUpdate {
args := data.([]interface{})
common.CheckVersion(args[len(args)-1].(int))
storage.Delete(ctx, common.LegacyOwnerKey) storage.Delete(ctx, common.LegacyOwnerKey)
return return
} }

View file

@ -47,6 +47,9 @@ var (
// _deploy sets up initial alphabet node keys. // _deploy sets up initial alphabet node keys.
func _deploy(data interface{}, isUpdate bool) { func _deploy(data interface{}, isUpdate bool) {
if isUpdate { if isUpdate {
args := data.([]interface{})
common.CheckVersion(args[len(args)-1].(int))
ctx := storage.GetContext() ctx := storage.GetContext()
nodes := getNodes(ctx, candidatesKey) nodes := getNodes(ctx, candidatesKey)
storage.Delete(ctx, candidatesKey) storage.Delete(ctx, candidatesKey)

View file

@ -32,6 +32,8 @@ func _deploy(data interface{}, isUpdate bool) {
ctx := storage.GetContext() ctx := storage.GetContext()
if isUpdate { if isUpdate {
args := data.([]interface{})
common.CheckVersion(args[len(args)-1].(int))
storage.Delete(ctx, common.LegacyOwnerKey) storage.Delete(ctx, common.LegacyOwnerKey)
return return
} }

View file

@ -68,6 +68,7 @@ func _deploy(data interface{}, isUpdate bool) {
addrContainer interop.Hash160 addrContainer interop.Hash160
keys []interop.PublicKey keys []interop.PublicKey
config [][]byte config [][]byte
version int
}) })
ln := len(args.config) ln := len(args.config)
@ -83,6 +84,7 @@ func _deploy(data interface{}, isUpdate bool) {
} }
if isUpdate { if isUpdate {
common.CheckVersion(args.version)
storage.Delete(ctx, common.LegacyOwnerKey) storage.Delete(ctx, common.LegacyOwnerKey)
return return
} }

View file

@ -90,6 +90,9 @@ func Update(nef []byte, manifest string, data interface{}) {
// _deploy initializes defaults (total supply and registration price) on contract deploy. // _deploy initializes defaults (total supply and registration price) on contract deploy.
func _deploy(data interface{}, isUpdate bool) { func _deploy(data interface{}, isUpdate bool) {
if isUpdate { if isUpdate {
args := data.([]interface{})
common.CheckVersion(args[len(args)-1].(int))
ctx := storage.GetContext() ctx := storage.GetContext()
committee := common.CommitteeAddress() committee := common.CommitteeAddress()
it := storage.Find(ctx, []byte{prefixRoot}, storage.KeysOnly|storage.RemovePrefix) it := storage.Find(ctx, []byte{prefixRoot}, storage.KeysOnly|storage.RemovePrefix)

View file

@ -28,6 +28,8 @@ func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) {
func _deploy(data interface{}, isUpdate bool) { func _deploy(data interface{}, isUpdate bool) {
if isUpdate { if isUpdate {
args := data.([]interface{})
common.CheckVersion(args[len(args)-1].(int))
return return
} }

View file

@ -19,9 +19,11 @@ func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) {
} }
} }
func _deploy(_ interface{}, isUpdate bool) { func _deploy(data interface{}, isUpdate bool) {
ctx := storage.GetContext()
if isUpdate { if isUpdate {
ctx := storage.GetContext()
args := data.([]interface{})
common.CheckVersion(args[len(args)-1].(int))
storage.Delete(ctx, common.LegacyOwnerKey) storage.Delete(ctx, common.LegacyOwnerKey)
return return
} }

View file

@ -22,6 +22,9 @@ func _deploy(data interface{}, isUpdate bool) {
ctx := storage.GetContext() ctx := storage.GetContext()
if isUpdate { if isUpdate {
args := data.([]interface{})
common.CheckVersion(args[len(args)-1].(int))
// Storage migration. // Storage migration.
storage.Delete(ctx, []byte("contractOwner")) storage.Delete(ctx, []byte("contractOwner"))

View file

@ -58,6 +58,8 @@ const (
// _deploy function sets up initial list of inner ring public keys. // _deploy function sets up initial list of inner ring public keys.
func _deploy(data interface{}, isUpdate bool) { func _deploy(data interface{}, isUpdate bool) {
if isUpdate { if isUpdate {
args := data.([]interface{})
common.CheckVersion(args[len(args)-1].(int))
return return
} }