-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Add] Get Accounts and Balances for NeoToken #3610
Merged
NGDAdmin
merged 14 commits into
neo-project:master
from
cschuchardt88:add/extensions/neotoken
Dec 31, 2024
Merged
Changes from 10 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4e951f1
[Add] Get Accounts and Balances for NeoToken
cschuchardt88 70e605a
Merge branch 'master' into add/extensions/neotoken
shargon cebb8e2
Made `Prefix_Account` internal
cschuchardt88 f8b724c
Merge branch 'master' into add/extensions/neotoken
cschuchardt88 c654f6b
Change `GetAccountBalance` to `BalanceOf`
cschuchardt88 2d767e5
Removed `BalanceOf` extension
cschuchardt88 db60e2f
Added null check
cschuchardt88 d98c401
Changed `Seek` to `Find` for `DataCache`
cschuchardt88 f95361e
Merge branch 'master' into add/extensions/neotoken
Jim8y 19bfaad
Merge branch 'master' into add/extensions/neotoken
cschuchardt88 d23a7ae
Merge branch 'master' into add/extensions/neotoken
Jim8y 4e21e22
Merge branch 'master' into add/extensions/neotoken
shargon 942e834
Merge branch 'master' into add/extensions/neotoken
NGDAdmin 879cc32
Merge branch 'master' into add/extensions/neotoken
NGDAdmin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (C) 2015-2024 The Neo Project. | ||
// | ||
// NeoTokenExtensions.cs file belongs to the neo project and is free | ||
// software distributed under the MIT software license, see the | ||
// accompanying file LICENSE in the main directory of the | ||
// repository or http://www.opensource.org/licenses/mit-license.php | ||
// for more details. | ||
// | ||
// Redistribution and use in source and binary forms with or without | ||
// modifications are permitted. | ||
|
||
using Neo.Persistence; | ||
using Neo.SmartContract; | ||
using Neo.SmartContract.Native; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Numerics; | ||
|
||
namespace Neo.Extensions | ||
{ | ||
public static class NeoTokenExtensions | ||
{ | ||
public static IEnumerable<(UInt160 Address, BigInteger Balance)> GetAccounts(this NeoToken neoToken, DataCache snapshot) | ||
{ | ||
if (neoToken is null) | ||
throw new ArgumentNullException(nameof(neoToken)); | ||
|
||
if (snapshot is null) | ||
throw new ArgumentNullException(nameof(snapshot)); | ||
|
||
var kb = new KeyBuilder(neoToken.Id, NeoToken.Prefix_Account); | ||
var prefixKey = kb.ToArray(); | ||
|
||
foreach (var (key, value) in snapshot.Find(prefixKey, SeekDirection.Forward)) | ||
{ | ||
var keyBytes = key.ToArray(); | ||
var addressHash = new UInt160(keyBytes.AsSpan(prefixKey.Length)); | ||
yield return new(addressHash, value.GetInteroperable<AccountState>().Balance); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (C) 2015-2024 The Neo Project. | ||
// | ||
// UT_NeoTokenExtensions.cs file belongs to the neo project and is free | ||
// software distributed under the MIT software license, see the | ||
// accompanying file LICENSE in the main directory of the | ||
// repository or http://www.opensource.org/licenses/mit-license.php | ||
// for more details. | ||
// | ||
// Redistribution and use in source and binary forms with or without | ||
// modifications are permitted. | ||
|
||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.Extensions; | ||
using Neo.SmartContract.Native; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Numerics; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Neo.UnitTests.Extensions | ||
{ | ||
[TestClass] | ||
public class UT_NeoTokenExtensions | ||
{ | ||
private NeoSystem system; | ||
|
||
[TestInitialize] | ||
public void Initialize() | ||
{ | ||
system = TestBlockchain.TheNeoSystem; | ||
} | ||
|
||
[TestCleanup] | ||
public void Clean() | ||
{ | ||
TestBlockchain.ResetStore(); | ||
} | ||
|
||
[TestMethod] | ||
public void TestGetAccounts() | ||
{ | ||
UInt160 expected = "0x9f8f056a53e39585c7bb52886418c7bed83d126b"; | ||
|
||
var accounts = NativeContract.NEO.GetAccounts(system.StoreView); | ||
var actual = accounts.FirstOrDefault(); | ||
|
||
Assert.AreEqual(expected, actual.Address); | ||
Assert.AreEqual(100000000, actual.Balance); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be useful for external callers to return
AccountState
instead of just balance. External caller can perform further selection by himself if only balance is needed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AccountState
only holdsbalance
andAccountState
was added for serialization, I believe.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably decimals will be soon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I confused
AccountState
withNeoAccountState
. So I mean that for Neo token it might be useful to returnNeoAccountState
because it contains additional voting information.Hope, it won't happen 🥲