forked from neo-project/neo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNotifyEventArgs.cs
96 lines (86 loc) · 3.01 KB
/
NotifyEventArgs.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright (C) 2015-2024 The Neo Project.
//
// NotifyEventArgs.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.IO;
using Neo.Network.P2P.Payloads;
using Neo.VM;
using Neo.VM.Types;
using System;
using Array = Neo.VM.Types.Array;
namespace Neo.SmartContract
{
/// <summary>
/// The <see cref="EventArgs"/> of <see cref="ApplicationEngine.Notify"/>.
/// </summary>
public class NotifyEventArgs : EventArgs, IInteroperable
{
/// <summary>
/// The container that containing the executed script.
/// </summary>
public IVerifiable ScriptContainer { get; }
/// <summary>
/// The script hash of the contract that sends the log.
/// </summary>
public UInt160 ScriptHash { get; }
/// <summary>
/// The name of the event.
/// </summary>
public string EventName { get; }
/// <summary>
/// The arguments of the event.
/// </summary>
public Array State { get; }
/// <summary>
/// Initializes a new instance of the <see cref="NotifyEventArgs"/> class.
/// </summary>
/// <param name="container">The container that containing the executed script.</param>
/// <param name="script_hash">The script hash of the contract that sends the log.</param>
/// <param name="eventName">The name of the event.</param>
/// <param name="state">The arguments of the event.</param>
public NotifyEventArgs(IVerifiable container, UInt160 script_hash, string eventName, Array state)
{
ScriptContainer = container;
ScriptHash = script_hash;
EventName = eventName;
State = state;
}
public void FromStackItem(StackItem stackItem)
{
throw new NotSupportedException();
}
public StackItem ToStackItem(ReferenceCounter referenceCounter)
{
return new Array(referenceCounter)
{
ScriptHash.ToArray(),
EventName,
State
};
}
public StackItem ToStackItem(ReferenceCounter referenceCounter, ApplicationEngine engine)
{
if (engine.IsHardforkEnabled(Hardfork.HF_Domovoi))
{
return new Array(referenceCounter)
{
ScriptHash.ToArray(),
EventName,
State.OnStack ? State : State.DeepCopy(true)
};
}
return new Array(referenceCounter)
{
ScriptHash.ToArray(),
EventName,
State
};
}
}
}