From 7938b93f8e624651df6c4e40f1e0be2e14e1291d Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 27 Jan 2021 21:28:53 +0800 Subject: [PATCH] Add tokens to NFT native contract (#2271) --- .../SmartContract/Native/NonfungibleToken.cs | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/neo/SmartContract/Native/NonfungibleToken.cs b/src/neo/SmartContract/Native/NonfungibleToken.cs index 35f799a57f..c572a3889d 100644 --- a/src/neo/SmartContract/Native/NonfungibleToken.cs +++ b/src/neo/SmartContract/Native/NonfungibleToken.cs @@ -1,3 +1,5 @@ +#pragma warning disable IDE0051 + using Neo.IO; using Neo.Persistence; using Neo.SmartContract.Iterators; @@ -121,19 +123,18 @@ public BigInteger BalanceOf(DataCache snapshot, UInt160 owner) } [ContractMethod(0_01000000, CallFlags.ReadStates)] - public IIterator TokensOf(DataCache snapshot, UInt160 owner) + private IIterator Tokens(DataCache snapshot) { - if (owner is null) - { - var results = snapshot.Find(new[] { Prefix_Token }).GetEnumerator(); - return new StorageIterator(results, FindOptions.ValuesOnly | FindOptions.DeserializeValues | FindOptions.PickField1, null); - } - else - { - NFTAccountState account = snapshot.TryGet(CreateStorageKey(Prefix_Account).Add(owner))?.GetInteroperable(); - IReadOnlyList tokens = account?.Tokens ?? (IReadOnlyList)System.Array.Empty(); - return new ArrayWrapper(tokens.Select(p => (StackItem)p).ToArray()); - } + var results = snapshot.Find(new[] { Prefix_Token }).GetEnumerator(); + return new StorageIterator(results, FindOptions.ValuesOnly | FindOptions.DeserializeValues | FindOptions.PickField1, null); + } + + [ContractMethod(0_01000000, CallFlags.ReadStates)] + private IIterator TokensOf(DataCache snapshot, UInt160 owner) + { + NFTAccountState account = snapshot.TryGet(CreateStorageKey(Prefix_Account).Add(owner))?.GetInteroperable(); + IReadOnlyList tokens = account?.Tokens ?? (IReadOnlyList)System.Array.Empty(); + return new ArrayWrapper(tokens.Select(p => (StackItem)p).ToArray()); } [ContractMethod(0_09000000, CallFlags.WriteStates | CallFlags.AllowNotify)]