Skip to content

Commit

Permalink
empty scripthash, all notifications (neo-project#1074)
Browse files Browse the repository at this point in the history
* empty scripthash, all notifications

* || to &&

* Fix ut
  • Loading branch information
igormcoelho authored and Tommo-L committed Jun 22, 2020
1 parent 9e89907 commit ee478c9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion neo.UnitTests/SmartContract/UT_InteropService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void Runtime_GetNotifications_Test()

// Receive all notifications

script.EmitPush(UInt160.Zero.ToArray());
script.EmitPush(new byte[0]);
script.EmitSysCall(InteropService.System_Runtime_GetNotifications);

// Execute
Expand Down
10 changes: 6 additions & 4 deletions neo/SmartContract/InteropService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,15 @@ private static bool Runtime_Serialize(ApplicationEngine engine)

private static bool Runtime_GetNotifications(ApplicationEngine engine)
{
var data = engine.CurrentContext.EvaluationStack.Pop().GetByteArray();
if (data.Length != UInt160.Length) return false;
byte[] data = engine.CurrentContext.EvaluationStack.Pop().GetByteArray();
if ((data.Length != 0) && (data.Length != UInt160.Length)) return false;

var hash = new UInt160(data);
IEnumerable<NotifyEventArgs> notifications = engine.Notifications;
if (!hash.Equals(UInt160.Zero))
if (data.Length == UInt160.Length) // must filter by scriptHash
{
var hash = new UInt160(data);
notifications = notifications.Where(p => p.ScriptHash == hash);
}

if (!engine.CheckArraySize(notifications.Count())) return false;
engine.CurrentContext.EvaluationStack.Push(notifications.Select(u => new VM.Types.Array(new StackItem[] { u.ScriptHash.ToArray(), u.State })).ToArray());
Expand Down

0 comments on commit ee478c9

Please sign in to comment.