From 1944a4332bb139a4e46d03003101d0ab2c1d0929 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Mon, 27 Dec 2021 10:15:36 +0300 Subject: [PATCH] [#202] *: remove owner from contract storage It is no longer used and should've be removed on update. Signed-off-by: Evgenii Stratonikov --- alphabet/alphabet_contract.go | 4 ++-- audit/audit_contract.go | 4 ++-- balance/balance_contract.go | 4 ++-- common/update.go | 3 +++ container/container_contract.go | 8 ++++---- neofsid/neofsid_contract.go | 1 + netmap/netmap_contract.go | 1 + proxy/proxy_contract.go | 3 +++ 8 files changed, 18 insertions(+), 10 deletions(-) diff --git a/alphabet/alphabet_contract.go b/alphabet/alphabet_contract.go index 8a85ef7..231795b 100644 --- a/alphabet/alphabet_contract.go +++ b/alphabet/alphabet_contract.go @@ -33,7 +33,9 @@ func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) { } func _deploy(data interface{}, isUpdate bool) { + ctx := storage.GetContext() if isUpdate { + storage.Delete(ctx, common.LegacyOwnerKey) return } @@ -46,8 +48,6 @@ func _deploy(data interface{}, isUpdate bool) { total int }) - ctx := storage.GetContext() - if len(args.addrNetmap) != interop.Hash160Len || !args.notaryDisabled && len(args.addrProxy) != interop.Hash160Len { panic("incorrect length of contract script hash") } diff --git a/audit/audit_contract.go b/audit/audit_contract.go index cfa3995..994cd7f 100644 --- a/audit/audit_contract.go +++ b/audit/audit_contract.go @@ -43,7 +43,9 @@ const ( ) func _deploy(data interface{}, isUpdate bool) { + ctx := storage.GetContext() if isUpdate { + storage.Delete(ctx, common.LegacyOwnerKey) return } @@ -52,8 +54,6 @@ func _deploy(data interface{}, isUpdate bool) { addrNetmap interop.Hash160 }) - ctx := storage.GetContext() - if len(args.addrNetmap) != interop.Hash160Len { panic("incorrect length of contract script hash") } diff --git a/balance/balance_contract.go b/balance/balance_contract.go index 8ac9f5d..fbf25b0 100644 --- a/balance/balance_contract.go +++ b/balance/balance_contract.go @@ -59,7 +59,9 @@ func init() { } func _deploy(data interface{}, isUpdate bool) { + ctx := storage.GetContext() if isUpdate { + storage.Delete(ctx, common.LegacyOwnerKey) return } @@ -69,8 +71,6 @@ func _deploy(data interface{}, isUpdate bool) { addrContainer interop.Hash160 }) - ctx := storage.GetContext() - if len(args.addrNetmap) != interop.Hash160Len || len(args.addrContainer) != interop.Hash160Len { panic("incorrect length of contract script hash") } diff --git a/common/update.go b/common/update.go index 8a865c1..07616b3 100644 --- a/common/update.go +++ b/common/update.go @@ -4,6 +4,9 @@ import ( "github.com/nspcc-dev/neo-go/pkg/interop/runtime" ) +// LegacyOwnerKey is storage key used to store contract owner. +const LegacyOwnerKey = "contractOwner" + // HasUpdateAccess returns true if contract can be updated. func HasUpdateAccess() bool { return runtime.CheckWitness(CommitteeAddress()) diff --git a/container/container_contract.go b/container/container_contract.go index 10b7e5b..cecbe50 100644 --- a/container/container_contract.go +++ b/container/container_contract.go @@ -83,6 +83,10 @@ func OnNEP11Payment(a interop.Hash160, b int, c []byte, d interface{}) { func _deploy(data interface{}, isUpdate bool) { ctx := storage.GetContext() + if isUpdate { + storage.Delete(ctx, common.LegacyOwnerKey) + return + } args := data.(struct { notaryDisabled bool @@ -93,10 +97,6 @@ func _deploy(data interface{}, isUpdate bool) { nnsRoot string }) - if isUpdate { - return - } - if len(args.addrNetmap) != interop.Hash160Len || len(args.addrBalance) != interop.Hash160Len || len(args.addrID) != interop.Hash160Len { diff --git a/neofsid/neofsid_contract.go b/neofsid/neofsid_contract.go index 8fc1e2f..be72594 100644 --- a/neofsid/neofsid_contract.go +++ b/neofsid/neofsid_contract.go @@ -33,6 +33,7 @@ func _deploy(data interface{}, isUpdate bool) { ctx := storage.GetContext() if isUpdate { + storage.Delete(ctx, common.LegacyOwnerKey) it := storage.Find(ctx, []byte{}, storage.None) for iterator.Next(it) { kv := iterator.Value(it).([][]byte) diff --git a/netmap/netmap_contract.go b/netmap/netmap_contract.go index fbd6796..7ce831d 100644 --- a/netmap/netmap_contract.go +++ b/netmap/netmap_contract.go @@ -83,6 +83,7 @@ func _deploy(data interface{}, isUpdate bool) { } if isUpdate { + storage.Delete(ctx, common.LegacyOwnerKey) return } diff --git a/proxy/proxy_contract.go b/proxy/proxy_contract.go index 84b0158..9841010 100644 --- a/proxy/proxy_contract.go +++ b/proxy/proxy_contract.go @@ -7,6 +7,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/interop/native/management" "github.com/nspcc-dev/neo-go/pkg/interop/native/neo" "github.com/nspcc-dev/neo-go/pkg/interop/runtime" + "github.com/nspcc-dev/neo-go/pkg/interop/storage" "github.com/nspcc-dev/neofs-contract/common" ) @@ -19,7 +20,9 @@ func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) { } func _deploy(_ interface{}, isUpdate bool) { + ctx := storage.GetContext() if isUpdate { + storage.Delete(ctx, common.LegacyOwnerKey) return }