Skip to content

Commit

Permalink
Change to BinarySearch
Browse files Browse the repository at this point in the history
  • Loading branch information
shargon committed Aug 14, 2020
1 parent 0eea25e commit 76153fe
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/neo/SmartContract/Native/PolicyContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,11 @@ public bool IsAnyAccountBlocked(StoreView snapshot, params UInt160[] hashes)
?.GetSerializableList<UInt160>().ToArray()
?? Array.Empty<UInt160>();

if (blockedList.Length == 0) return false;

foreach (var acc in hashes)
if (blockedList.Length > 0)
{
foreach (var blockAccount in blockedList)
foreach (var acc in hashes)
{
var comp = blockAccount.CompareTo(acc);
if (comp == 0) return true;
if (comp > 0) break; // It's already sorted
if (Array.BinarySearch(blockedList, acc) == 0) return true;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ public void Check_BlockAccount()
NativeContract.Policy.IsAnyAccountBlocked(snapshot).Should().BeFalse();
NativeContract.Policy.IsAnyAccountBlocked(snapshot, UInt160.Zero).Should().BeFalse();
NativeContract.Policy.IsAnyAccountBlocked(snapshot, UInt160.Zero, UInt160.Parse("0xa400ff00ff00ff00ff00ff00ff00ff00ff00ff01")).Should().BeTrue();
NativeContract.Policy.IsAnyAccountBlocked(snapshot, UInt160.Parse("0xa400ff00ff00ff00ff00ff00ff00ff00ff00ff01"), UInt160.Zero).Should().BeTrue();

ret = NativeContract.Policy.Call(snapshot, "getBlockedAccounts");
ret.Should().BeOfType<VM.Types.Array>();
Expand Down

0 comments on commit 76153fe

Please sign in to comment.