From 64b012f76d3dabf236b0dfca79c7e3c7d821c556 Mon Sep 17 00:00:00 2001 From: Harry Date: Thu, 10 Dec 2020 10:14:13 -0800 Subject: [PATCH 1/6] add ManagementContract.ListContracts --- src/neo/SmartContract/Native/ManagementContract.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/neo/SmartContract/Native/ManagementContract.cs b/src/neo/SmartContract/Native/ManagementContract.cs index d040480282..e48b342888 100644 --- a/src/neo/SmartContract/Native/ManagementContract.cs +++ b/src/neo/SmartContract/Native/ManagementContract.cs @@ -6,6 +6,8 @@ using Neo.Persistence; using Neo.SmartContract.Manifest; using System; +using System.Collections.Generic; +using System.Linq; using System.Numerics; namespace Neo.SmartContract.Native @@ -44,6 +46,13 @@ internal override void OnPersist(ApplicationEngine engine) } } + static Lazy listContractsPrefix = new Lazy(() => new KeyBuilder(NativeContract.Management.Id, 8).ToArray()); + + public IEnumerable ListContracts(StoreView snapshot) + { + return snapshot.Storages.Find(listContractsPrefix.Value).Select(kvp => kvp.Value.GetInteroperable()); + } + [ContractMethod(0_01000000, CallFlags.ReadStates)] public ContractState GetContract(StoreView snapshot, UInt160 hash) { From 7e5a607a212a0d5c0df06516e289cd7f5b313cc8 Mon Sep 17 00:00:00 2001 From: Shargon Date: Fri, 11 Dec 2020 09:13:37 +0100 Subject: [PATCH 2/6] Remove static --- src/neo/SmartContract/Native/ManagementContract.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/neo/SmartContract/Native/ManagementContract.cs b/src/neo/SmartContract/Native/ManagementContract.cs index e48b342888..ef005b0418 100644 --- a/src/neo/SmartContract/Native/ManagementContract.cs +++ b/src/neo/SmartContract/Native/ManagementContract.cs @@ -20,6 +20,7 @@ public sealed class ManagementContract : NativeContract private const byte Prefix_NextAvailableId = 15; private const byte Prefix_Contract = 8; + private Lazy listContractsPrefix = new Lazy(() => new KeyBuilder(NativeContract.Management.Id, 8).ToArray()); private int GetNextAvailableId(StoreView snapshot) { @@ -46,8 +47,6 @@ internal override void OnPersist(ApplicationEngine engine) } } - static Lazy listContractsPrefix = new Lazy(() => new KeyBuilder(NativeContract.Management.Id, 8).ToArray()); - public IEnumerable ListContracts(StoreView snapshot) { return snapshot.Storages.Find(listContractsPrefix.Value).Select(kvp => kvp.Value.GetInteroperable()); From 9ef2710b3d47f4d40d0a9584e39e5b34480fa887 Mon Sep 17 00:00:00 2001 From: Shargon Date: Fri, 11 Dec 2020 09:14:48 +0100 Subject: [PATCH 3/6] Use const --- src/neo/SmartContract/Native/ManagementContract.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/neo/SmartContract/Native/ManagementContract.cs b/src/neo/SmartContract/Native/ManagementContract.cs index ef005b0418..209321ea1b 100644 --- a/src/neo/SmartContract/Native/ManagementContract.cs +++ b/src/neo/SmartContract/Native/ManagementContract.cs @@ -20,7 +20,7 @@ public sealed class ManagementContract : NativeContract private const byte Prefix_NextAvailableId = 15; private const byte Prefix_Contract = 8; - private Lazy listContractsPrefix = new Lazy(() => new KeyBuilder(NativeContract.Management.Id, 8).ToArray()); + private Lazy listContractsPrefix = new Lazy(() => new KeyBuilder(NativeContract.Management.Id, Prefix_Contract).ToArray()); private int GetNextAvailableId(StoreView snapshot) { From b2ef5e61b1675828fcdba9ec185a87b94adf8235 Mon Sep 17 00:00:00 2001 From: Shargon Date: Fri, 11 Dec 2020 10:36:34 +0100 Subject: [PATCH 4/6] Remove var --- src/neo/SmartContract/Native/ManagementContract.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/neo/SmartContract/Native/ManagementContract.cs b/src/neo/SmartContract/Native/ManagementContract.cs index 209321ea1b..405b62121f 100644 --- a/src/neo/SmartContract/Native/ManagementContract.cs +++ b/src/neo/SmartContract/Native/ManagementContract.cs @@ -20,7 +20,6 @@ public sealed class ManagementContract : NativeContract private const byte Prefix_NextAvailableId = 15; private const byte Prefix_Contract = 8; - private Lazy listContractsPrefix = new Lazy(() => new KeyBuilder(NativeContract.Management.Id, Prefix_Contract).ToArray()); private int GetNextAvailableId(StoreView snapshot) { @@ -49,7 +48,8 @@ internal override void OnPersist(ApplicationEngine engine) public IEnumerable ListContracts(StoreView snapshot) { - return snapshot.Storages.Find(listContractsPrefix.Value).Select(kvp => kvp.Value.GetInteroperable()); + byte[] listContractsPrefix = new KeyBuilder(NativeContract.Management.Id, Prefix_Contract).ToArray(); + return snapshot.Storages.Find(listContractsPrefix).Select(kvp => kvp.Value.GetInteroperable()); } [ContractMethod(0_01000000, CallFlags.ReadStates)] From 8051399f99a09397077ce40b4d4e06fd7ed20140 Mon Sep 17 00:00:00 2001 From: Shargon Date: Fri, 11 Dec 2020 13:35:43 +0100 Subject: [PATCH 5/6] Use CreateStorageKey --- src/neo/SmartContract/Native/ManagementContract.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/neo/SmartContract/Native/ManagementContract.cs b/src/neo/SmartContract/Native/ManagementContract.cs index 405b62121f..0324c93c59 100644 --- a/src/neo/SmartContract/Native/ManagementContract.cs +++ b/src/neo/SmartContract/Native/ManagementContract.cs @@ -48,7 +48,7 @@ internal override void OnPersist(ApplicationEngine engine) public IEnumerable ListContracts(StoreView snapshot) { - byte[] listContractsPrefix = new KeyBuilder(NativeContract.Management.Id, Prefix_Contract).ToArray(); + byte[] listContractsPrefix = CreateStorageKey(Prefix_Contract).ToArray(); return snapshot.Storages.Find(listContractsPrefix).Select(kvp => kvp.Value.GetInteroperable()); } From 457f2a9701a6291d4605ec3e02f3fd35e487cb88 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Sat, 12 Dec 2020 03:15:55 +0800 Subject: [PATCH 6/6] Update ManagementContract.cs --- src/neo/SmartContract/Native/ManagementContract.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/neo/SmartContract/Native/ManagementContract.cs b/src/neo/SmartContract/Native/ManagementContract.cs index c73c62d4fb..4a76cd831c 100644 --- a/src/neo/SmartContract/Native/ManagementContract.cs +++ b/src/neo/SmartContract/Native/ManagementContract.cs @@ -45,18 +45,18 @@ internal override void OnPersist(ApplicationEngine engine) } } - public IEnumerable ListContracts(StoreView snapshot) - { - byte[] listContractsPrefix = CreateStorageKey(Prefix_Contract).ToArray(); - return snapshot.Storages.Find(listContractsPrefix).Select(kvp => kvp.Value.GetInteroperable()); - } - [ContractMethod(0_01000000, CallFlags.ReadStates)] public ContractState GetContract(StoreView snapshot, UInt160 hash) { return snapshot.Storages.TryGet(CreateStorageKey(Prefix_Contract).Add(hash))?.GetInteroperable(); } + public IEnumerable ListContracts(StoreView snapshot) + { + byte[] listContractsPrefix = CreateStorageKey(Prefix_Contract).ToArray(); + return snapshot.Storages.Find(listContractsPrefix).Select(kvp => kvp.Value.GetInteroperable()); + } + [ContractMethod(0, CallFlags.WriteStates)] private ContractState Deploy(ApplicationEngine engine, byte[] nefFile, byte[] manifest) {