From 622a83e01431ba449acf3e7526c413aa1d028952 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Tue, 27 Apr 2021 13:48:40 +0300 Subject: [PATCH] [#74] Add notary disabled option to contracts Signed-off-by: Alex Vanin --- alphabet/alphabet_contract.go | 10 +++++++++- audit/audit_contract.go | 7 ++++++- balance/balance_contract.go | 9 ++++++++- container/container_contract.go | 12 ++++++++++-- neofs/neofs_contract.go | 13 ++++++++++--- neofsid/neofsid_contract.go | 9 ++++++++- netmap/netmap_contract.go | 16 ++++++++++++---- reputation/reputation_contract.go | 10 +++++++++- 8 files changed, 72 insertions(+), 14 deletions(-) diff --git a/alphabet/alphabet_contract.go b/alphabet/alphabet_contract.go index d6b5671..4724409 100644 --- a/alphabet/alphabet_contract.go +++ b/alphabet/alphabet_contract.go @@ -19,6 +19,8 @@ const ( totalKey = "threshold" nameKey = "name" + notaryDisabledKey = "notary" + version = 1 ) @@ -30,7 +32,7 @@ func OnNEP17Payment(from interop.Hash160, amount int, data interface{}) { } } -func Init(owner interop.Hash160, addrNetmap, addrProxy interop.Hash160, name string, index, total int) { +func Init(notaryDisabled bool, owner interop.Hash160, addrNetmap, addrProxy interop.Hash160, name string, index, total int) { ctx := storage.GetContext() if !common.HasUpdateAccess(ctx) { @@ -48,6 +50,12 @@ func Init(owner interop.Hash160, addrNetmap, addrProxy interop.Hash160, name str storage.Put(ctx, indexKey, index) storage.Put(ctx, totalKey, total) + // initialize the way to collect signatures + storage.Put(ctx, notaryDisabledKey, notaryDisabled) + if notaryDisabled { + common.InitVote(ctx) + } + runtime.Log(name + " contract initialized") } diff --git a/audit/audit_contract.go b/audit/audit_contract.go index 400c692..47b7794 100644 --- a/audit/audit_contract.go +++ b/audit/audit_contract.go @@ -38,9 +38,11 @@ const ( version = 1 netmapContractKey = "netmapScriptHash" + + notaryDisabledKey = "notary" ) -func Init(owner interop.Hash160, addrNetmap interop.Hash160) { +func Init(notaryDisabled bool, owner interop.Hash160, addrNetmap interop.Hash160) { ctx := storage.GetContext() if !common.HasUpdateAccess(ctx) { @@ -54,6 +56,9 @@ func Init(owner interop.Hash160, addrNetmap interop.Hash160) { storage.Put(ctx, common.OwnerKey, owner) storage.Put(ctx, netmapContractKey, addrNetmap) + // initialize the way to collect signatures + storage.Put(ctx, notaryDisabledKey, notaryDisabled) + runtime.Log("audit contract initialized") } diff --git a/balance/balance_contract.go b/balance/balance_contract.go index e91f9bf..0a59f6d 100644 --- a/balance/balance_contract.go +++ b/balance/balance_contract.go @@ -40,6 +40,7 @@ const ( netmapContractKey = "netmapScriptHash" containerContractKey = "containerScriptHash" + notaryDisabledKey = "notary" ) var ( @@ -62,7 +63,7 @@ func init() { token = CreateToken() } -func Init(owner, addrNetmap, addrContainer interop.Hash160) { +func Init(notaryDisabled bool, owner, addrNetmap, addrContainer interop.Hash160) { ctx := storage.GetContext() if !common.HasUpdateAccess(ctx) { @@ -77,6 +78,12 @@ func Init(owner, addrNetmap, addrContainer interop.Hash160) { storage.Put(ctx, netmapContractKey, addrNetmap) storage.Put(ctx, containerContractKey, addrContainer) + // initialize the way to collect signatures + storage.Put(ctx, notaryDisabledKey, notaryDisabled) + if notaryDisabled { + common.InitVote(ctx) + } + runtime.Log("balance contract initialized") } diff --git a/container/container_contract.go b/container/container_contract.go index 4271d95..e15a02e 100644 --- a/container/container_contract.go +++ b/container/container_contract.go @@ -41,7 +41,9 @@ const ( neofsIDContractKey = "identityScriptHash" balanceContractKey = "balanceScriptHash" netmapContractKey = "netmapScriptHash" - containerFeeKey = "ContainerFee" + notaryDisabledKey = "notary" + + containerFeeKey = "ContainerFee" containerIDSize = 32 // SHA256 size @@ -53,7 +55,7 @@ var ( eACLPrefix = []byte("eACL") ) -func Init(owner, addrNetmap, addrBalance, addrID interop.Hash160) { +func Init(notaryDisabled bool, owner, addrNetmap, addrBalance, addrID interop.Hash160) { ctx := storage.GetContext() if !common.HasUpdateAccess(ctx) { @@ -69,6 +71,12 @@ func Init(owner, addrNetmap, addrBalance, addrID interop.Hash160) { storage.Put(ctx, balanceContractKey, addrBalance) storage.Put(ctx, neofsIDContractKey, addrID) + // initialize the way to collect signatures + storage.Put(ctx, notaryDisabledKey, notaryDisabled) + if notaryDisabled { + common.InitVote(ctx) + } + runtime.Log("container contract initialized") } diff --git a/neofs/neofs_contract.go b/neofs/neofs_contract.go index 0bb9545..e993419 100644 --- a/neofs/neofs_contract.go +++ b/neofs/neofs_contract.go @@ -57,8 +57,9 @@ const ( version = 3 - alphabetKey = "alphabet" - candidatesKey = "candidates" + alphabetKey = "alphabet" + candidatesKey = "candidates" + notaryDisabledKey = "notary" processingContractKey = "processingScriptHash" @@ -75,7 +76,7 @@ var ( ) // Init set up initial alphabet node keys. -func Init(owner, addrProc interop.Hash160, args []interop.PublicKey) bool { +func Init(notaryDisabled bool, owner, addrProc interop.Hash160, args []interop.PublicKey) bool { ctx := storage.GetContext() if !common.HasUpdateAccess(ctx) { @@ -107,6 +108,12 @@ func Init(owner, addrProc interop.Hash160, args []interop.PublicKey) bool { storage.Put(ctx, common.OwnerKey, owner) storage.Put(ctx, processingContractKey, addrProc) + // initialize the way to collect signatures + storage.Put(ctx, notaryDisabledKey, notaryDisabled) + if notaryDisabled { + common.InitVote(ctx) + } + runtime.Log("neofs: contract initialized") return true diff --git a/neofsid/neofsid_contract.go b/neofsid/neofsid_contract.go index da9f43d..929c85d 100644 --- a/neofsid/neofsid_contract.go +++ b/neofsid/neofsid_contract.go @@ -20,9 +20,10 @@ const ( netmapContractKey = "netmapScriptHash" containerContractKey = "containerScriptHash" + notaryDisabledKey = "notary" ) -func Init(owner, addrNetmap, addrContainer interop.Hash160) { +func Init(notaryDisabled bool, owner, addrNetmap, addrContainer interop.Hash160) { ctx := storage.GetContext() if !common.HasUpdateAccess(ctx) { @@ -37,6 +38,12 @@ func Init(owner, addrNetmap, addrContainer interop.Hash160) { storage.Put(ctx, netmapContractKey, addrNetmap) storage.Put(ctx, containerContractKey, addrContainer) + // initialize the way to collect signatures + storage.Put(ctx, notaryDisabledKey, notaryDisabled) + if notaryDisabled { + common.InitVote(ctx) + } + runtime.Log("neofsid contract initialized") } diff --git a/netmap/netmap_contract.go b/netmap/netmap_contract.go index 085d8b9..f7c73a5 100644 --- a/netmap/netmap_contract.go +++ b/netmap/netmap_contract.go @@ -32,8 +32,9 @@ type ( const ( version = 1 - netmapKey = "netmap" - configuredKey = "initconfig" + netmapKey = "netmap" + configuredKey = "initconfig" + notaryDisabledKey = "notary" snapshot0Key = "snapshotCurrent" snapshot1Key = "snapshotPrevious" @@ -41,7 +42,8 @@ const ( containerContractKey = "containerScriptHash" balanceContractKey = "balanceScriptHash" - cleanupEpochMethod = "newEpoch" + + cleanupEpochMethod = "newEpoch" ) const ( @@ -56,7 +58,7 @@ var ( // Init function sets up initial list of inner ring public keys and should // be invoked once at neofs infrastructure setup. -func Init(owner, addrBalance, addrContainer interop.Hash160) { +func Init(notaryDisabled bool, owner, addrBalance, addrContainer interop.Hash160) { ctx := storage.GetContext() if !common.HasUpdateAccess(ctx) { @@ -80,6 +82,12 @@ func Init(owner, addrBalance, addrContainer interop.Hash160) { storage.Put(ctx, balanceContractKey, addrBalance) storage.Put(ctx, containerContractKey, addrContainer) + // initialize the way to collect signatures + storage.Put(ctx, notaryDisabledKey, notaryDisabled) + if notaryDisabled { + common.InitVote(ctx) + } + runtime.Log("netmap contract initialized") } diff --git a/reputation/reputation_contract.go b/reputation/reputation_contract.go index e4640fa..2069a0d 100644 --- a/reputation/reputation_contract.go +++ b/reputation/reputation_contract.go @@ -11,10 +11,12 @@ import ( ) const ( + notaryDisabledKey = "notary" + version = 1 ) -func Init(owner interop.Hash160) { +func Init(notaryDisabled bool, owner interop.Hash160) { ctx := storage.GetContext() if !common.HasUpdateAccess(ctx) { @@ -23,6 +25,12 @@ func Init(owner interop.Hash160) { storage.Put(ctx, common.OwnerKey, owner) + // initialize the way to collect signatures + storage.Put(ctx, notaryDisabledKey, notaryDisabled) + if notaryDisabled { + common.InitVote(ctx) + } + runtime.Log("reputation contract initialized") }