Skip to content

Commit

Permalink
Update RpcApplicationLog.cs in RpcClient (#395)
Browse files Browse the repository at this point in the history
* fixed-bug-1021

* Update src/RpcServer/RpcServer.SmartContract.cs

* 😂

* Update RpcApplicationLog.cs in RpcClient

* update

* Fixed UT

* ???

* update

* UT

Co-authored-by: Shargon <[email protected]>
Co-authored-by: Owen Zhang <[email protected]>
Co-authored-by: superboyiii <[email protected]>
  • Loading branch information
4 people authored Nov 16, 2020
1 parent 7cee1a4 commit 2ae6a97
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 136 deletions.
34 changes: 30 additions & 4 deletions src/RpcClient/Models/RpcApplicationLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,34 @@ public class RpcApplicationLog
{
public UInt256 TxId { get; set; }

public UInt256 BlockHash { get; set; }

public List<Execution> Executions { get; set; }

public JObject ToJson()
{
JObject json = new JObject();
if (TxId != null)
json["txid"] = TxId.ToString();
if (BlockHash != null)
json["blockhash"] = BlockHash.ToString();
json["executions"] = Executions.Select(p => p.ToJson()).ToArray();
return json;
}

public static RpcApplicationLog FromJson(JObject json)
{
return new RpcApplicationLog
{
TxId = json["txid"] is null ? null : UInt256.Parse(json["txid"].AsString()),
BlockHash = json["blockhash"] is null ? null : UInt256.Parse(json["blockhash"].AsString()),
Executions = ((JArray)json["executions"]).Select(p => Execution.FromJson(p)).ToList(),
};
}
}

public class Execution
{
public TriggerType Trigger { get; set; }

public VMState VMState { get; set; }
Expand All @@ -24,7 +52,6 @@ public class RpcApplicationLog
public JObject ToJson()
{
JObject json = new JObject();
json["txid"] = TxId?.ToString();
json["trigger"] = Trigger;
json["vmstate"] = VMState;
json["gasconsumed"] = GasConsumed.ToString();
Expand All @@ -33,11 +60,10 @@ public JObject ToJson()
return json;
}

public static RpcApplicationLog FromJson(JObject json)
public static Execution FromJson(JObject json)
{
return new RpcApplicationLog
return new Execution
{
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()),
Expand Down
11 changes: 11 additions & 0 deletions src/RpcClient/RpcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Neo.Ledger;
using Neo.Network.P2P.Payloads;
using Neo.Network.RPC.Models;
using Neo.SmartContract;
using Neo.SmartContract.Manifest;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -543,6 +544,16 @@ public async Task<RpcApplicationLog> GetApplicationLogAsync(string txHash)
return RpcApplicationLog.FromJson(result);
}

/// <summary>
/// Returns the contract log based on the specified txHash. The complete contract logs are stored under the ApplicationLogs directory.
/// This method is provided by the plugin ApplicationLogs.
/// </summary>
public async Task<RpcApplicationLog> GetApplicationLogAsync(string txHash, TriggerType triggerType)
{
var result = await RpcSendAsync(GetRpcName(), txHash, triggerType).ConfigureAwait(false);
return RpcApplicationLog.FromJson(result);
}

/// <summary>
/// Returns all the NEP-5 transaction information occurred in the specified address.
/// This method is provided by the plugin RpcNep5Tracker.
Expand Down
258 changes: 126 additions & 132 deletions tests/Neo.Network.RPC.Tests/RpcTestCases.json
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@
"jsonrpc": "2.0",
"id": 1,
"result": {
"magic": 0,
"magic": 0,
"tcpport": 20333,
"wsport": 20334,
"nonce": 592651621,
Expand Down Expand Up @@ -1201,162 +1201,156 @@
"Request": {
"jsonrpc": "2.0",
"method": "getapplicationlog",
"params": [ "0x183cd84359cd9f8b956afcd02403ec07361c1dba55f0800241b4ef2b28e88bbb" ],
"params": [ "0x6ea186fe714b8168ede3b78461db8945c06d867da649852352dbe7cbf1ba3724" ],
"id": 1
},
"Response": {
"jsonrpc": "2.0",
"id": "1",
"id": 1,
"result": {
"txid": "0xe36f62923deb64376e5e982e19b60afc65faca8d9e8eb71ac12f7298ce32ef7b",
"trigger": "Application",
"vmstate": "HALT",
"gasconsumed": "5814860",
"stack": [
"blockhash": "0x6ea186fe714b8168ede3b78461db8945c06d867da649852352dbe7cbf1ba3724",
"executions": [
{
"type": "Array",
"value": [
{
"type": "Any"
},
{
"type": "Integer",
"value": "1"
},
{
"type": "Integer",
"value": "1223"
},
{
"type": "ByteString",
"value": "dGVzdHFxd2FzZGFz"
},
{
"type": "Buffer",
"value": "CAwiNQw="
},
"trigger": "OnPersist",
"vmstate": "HALT",
"gasconsumed": "2031260",
"stack": [],
"notifications": [
{
"type": "Array",
"value": [
{
"type": "ByteString",
"value": "YWE="
},
{
"type": "ByteString",
"value": "YmI="
},
{
"type": "ByteString",
"value": "Y2Mw"
}
]
"contract": "0x668e0c1f9d7b70a99dd9e06eadd4c784d641afbc",
"eventname": "Transfer",
"state": {
"type": "Array",
"value": [
{
"type": "ByteString",
"value": "CqOHtT6Wt5iaYxQxoFbdH0CgQvY="
},
{
"type": "Any"
},
{
"type": "Integer",
"value": "18083410"
}
]
}
},
{
"type": "Map",
"value": [
{
"key": {
"type": "Integer",
"value": "2"
"contract": "0x668e0c1f9d7b70a99dd9e06eadd4c784d641afbc",
"eventname": "Transfer",
"state": {
"type": "Array",
"value": [
{
"type": "Any"
},
"value": {
{
"type": "ByteString",
"value": "z6LDQN4w1uEMToIZiPSxToNRPog="
},
{
"type": "Integer",
"value": "12"
"value": "1252390"
}
},
{
"key": {
"type": "Integer",
"value": "0"
]
}
}
]
},
{
"trigger": "PostPersist",
"vmstate": "HALT",
"gasconsumed": "2031260",
"stack": [],
"notifications": [
{
"contract": "0x668e0c1f9d7b70a99dd9e06eadd4c784d641afbc",
"eventname": "Transfer",
"state": {
"type": "Array",
"value": [
{
"type": "Any"
},
"value": {
{
"type": "ByteString",
"value": "z6LDQN4w1uEMToIZiPSxToNRPog="
},
{
"type": "Integer",
"value": "24"
"value": "50000000"
}
}
]
]
}
}
]
}
],
"notifications": [
]
}
}
},
{
"Name": "getapplicationlogasync_triggertype",
"Request": {
"jsonrpc": "2.0",
"method": "getapplicationlog",
"params": [ "0x6ea186fe714b8168ede3b78461db8945c06d867da649852352dbe7cbf1ba3724", "OnPersist" ],
"id": 1
},
"Response": {
"jsonrpc": "2.0",
"id": 1,
"result": {
"blockhash": "0x6ea186fe714b8168ede3b78461db8945c06d867da649852352dbe7cbf1ba3724",
"executions": [
{
"contract": "0xbfe215933f29b29dacf0e8383722a62974ac8aa6",
"eventname": "event_name",
"state": {
"type": "Array",
"value": [
{
"trigger": "OnPersist",
"vmstate": "HALT",
"gasconsumed": "2031260",
"stack": [],
"notifications": [
{
"contract": "0x668e0c1f9d7b70a99dd9e06eadd4c784d641afbc",
"eventname": "Transfer",
"state": {
"type": "Array",
"value": [
{
"type": "Array",
"value": [
{
"type": "Integer",
"value": "1"
},
{
"type": "Integer",
"value": "1223"
},
{
"type": "ByteString",
"value": "dGVzdHFxd2FzZGFz"
},
{
"type": "Buffer",
"value": "CAwiNQw="
},
{
"type": "Array",
"value": [
{
"type": "ByteString",
"value": "YWE="
},
{
"type": "ByteString",
"value": "YmI="
},
{
"type": "ByteString",
"value": "Y2Mw"
}
]
},
{
"type": "Map",
"value": [
{
"key": {
"type": "Integer",
"value": "2"
},
"value": {
"type": "Integer",
"value": "12"
}
},
{
"key": {
"type": "Integer",
"value": "0"
},
"value": {
"type": "Integer",
"value": "24"
}
}
]
}
]
"type": "ByteString",
"value": "CqOHtT6Wt5iaYxQxoFbdH0CgQvY="
},
{
"type": "Any"
},
{
"type": "Integer",
"value": "18083410"
}
]
}
]
}
},
{
"contract": "0x668e0c1f9d7b70a99dd9e06eadd4c784d641afbc",
"eventname": "Transfer",
"state": {
"type": "Array",
"value": [
{
"type": "Any"
},
{
"type": "ByteString",
"value": "z6LDQN4w1uEMToIZiPSxToNRPog="
},
{
"type": "Integer",
"value": "1252390"
}
]
}
}
]
}
]
}
Expand Down
Loading

0 comments on commit 2ae6a97

Please sign in to comment.