-
Notifications
You must be signed in to change notification settings - Fork 100
/
RpcApplicationLog.cs
77 lines (64 loc) · 2.38 KB
/
RpcApplicationLog.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
using Neo.IO.Json;
using Neo.SmartContract;
using Neo.VM;
using Neo.VM.Types;
using System.Collections.Generic;
using System.Linq;
namespace Neo.Network.RPC.Models
{
public class RpcApplicationLog
{
public UInt256 TxId { get; set; }
public TriggerType Trigger { get; set; }
public VMState VMState { get; set; }
public long GasConsumed { get; set; }
public List<StackItem> Stack { get; set; }
public List<RpcNotifyEventArgs> Notifications { get; set; }
public JObject ToJson()
{
JObject json = new JObject();
json["txid"] = TxId?.ToString();
json["trigger"] = Trigger;
json["vmstate"] = VMState;
json["gasconsumed"] = GasConsumed.ToString();
json["stack"] = Stack.Select(q => q.ToJson()).ToArray();
json["notifications"] = Notifications.Select(q => q.ToJson()).ToArray();
return json;
}
public static RpcApplicationLog FromJson(JObject json)
{
return new RpcApplicationLog
{
TxId = json["txid"] is null ? null : UInt256.Parse(json["txid"].AsString()),
Trigger = json["trigger"].TryGetEnum<TriggerType>(),
VMState = json["vmstate"].TryGetEnum<VMState>(),
GasConsumed = long.Parse(json["gasconsumed"].AsString()),
Stack = ((JArray)json["stack"]).Select(p => Utility.StackItemFromJson(p)).ToList(),
Notifications = ((JArray)json["notifications"]).Select(p => RpcNotifyEventArgs.FromJson(p)).ToList()
};
}
}
public class RpcNotifyEventArgs
{
public UInt160 Contract { get; set; }
public string EventName { get; set; }
public StackItem State { get; set; }
public JObject ToJson()
{
JObject json = new JObject();
json["contract"] = Contract.ToString();
json["eventname"] = EventName;
json["state"] = State.ToJson();
return json;
}
public static RpcNotifyEventArgs FromJson(JObject json)
{
return new RpcNotifyEventArgs
{
Contract = json["contract"].ToScriptHash(),
EventName = json["eventname"].AsString(),
State = Utility.StackItemFromJson(json["state"])
};
}
}
}