From c7997a93e0b878c75bddf24dd41e57efb003c337 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=BF=97=E5=90=8C?= Date: Wed, 21 Oct 2020 14:59:01 +0800 Subject: [PATCH 1/9] fixed-bug-1021 --- src/RpcServer/RpcServer.SmartContract.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RpcServer/RpcServer.SmartContract.cs b/src/RpcServer/RpcServer.SmartContract.cs index f5cf6cbfc..3de9c924f 100644 --- a/src/RpcServer/RpcServer.SmartContract.cs +++ b/src/RpcServer/RpcServer.SmartContract.cs @@ -79,7 +79,7 @@ private JObject GetInvokeResult(byte[] script, Signers signers = null) } if (engine.State != VMState.FAULT) { - ProcessInvokeWithWallet(json, signers); + ProcessInvokeWithWallet(json, null, signers); } return json; } From 7c9f02bb4bb73841a3cc2cd85dc67b59d643edc9 Mon Sep 17 00:00:00 2001 From: Shargon Date: Wed, 21 Oct 2020 09:22:58 +0200 Subject: [PATCH 2/9] Update src/RpcServer/RpcServer.SmartContract.cs --- src/RpcServer/RpcServer.SmartContract.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RpcServer/RpcServer.SmartContract.cs b/src/RpcServer/RpcServer.SmartContract.cs index 3de9c924f..8203bd7c6 100644 --- a/src/RpcServer/RpcServer.SmartContract.cs +++ b/src/RpcServer/RpcServer.SmartContract.cs @@ -79,7 +79,7 @@ private JObject GetInvokeResult(byte[] script, Signers signers = null) } if (engine.State != VMState.FAULT) { - ProcessInvokeWithWallet(json, null, signers); + ProcessInvokeWithWallet(json, signers: signers); } return json; } From 1079aa36eb031f2d2672033ecd3cdb2e689672ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=BF=97=E5=90=8C?= Date: Wed, 21 Oct 2020 17:48:21 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=F0=9F=98=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/RpcServer/RpcServer.SmartContract.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RpcServer/RpcServer.SmartContract.cs b/src/RpcServer/RpcServer.SmartContract.cs index 8203bd7c6..f5cf6cbfc 100644 --- a/src/RpcServer/RpcServer.SmartContract.cs +++ b/src/RpcServer/RpcServer.SmartContract.cs @@ -79,7 +79,7 @@ private JObject GetInvokeResult(byte[] script, Signers signers = null) } if (engine.State != VMState.FAULT) { - ProcessInvokeWithWallet(json, signers: signers); + ProcessInvokeWithWallet(json, signers); } return json; } From 6d0517c6a0538376fe08d88013802e94184524cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=BF=97=E5=90=8C?= Date: Wed, 11 Nov 2020 16:15:23 +0800 Subject: [PATCH 4/9] Update RpcApplicationLog.cs in RpcClient --- src/RpcClient/Models/RpcApplicationLog.cs | 31 ++++++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/RpcClient/Models/RpcApplicationLog.cs b/src/RpcClient/Models/RpcApplicationLog.cs index 205835e9c..038a7afff 100644 --- a/src/RpcClient/Models/RpcApplicationLog.cs +++ b/src/RpcClient/Models/RpcApplicationLog.cs @@ -11,6 +11,31 @@ public class RpcApplicationLog { public UInt256 TxId { get; set; } + public UInt256 BlockHash { get; set; } + + public List Executions { get; set; } + + public JObject ToJson() + { + JObject json = new JObject(); + json["txid"] = TxId?.ToString(); + json["blockhash"] = BlockHash?.ToString(); + 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; } @@ -24,7 +49,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(); @@ -33,11 +57,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(), VMState = json["vmstate"].TryGetEnum(), GasConsumed = long.Parse(json["gasconsumed"].AsString()), From 9718cc6d26a52d8f40f539494d48e5db39f065d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=BF=97=E5=90=8C?= Date: Wed, 11 Nov 2020 20:01:45 +0800 Subject: [PATCH 5/9] update --- src/RpcClient/Models/RpcApplicationLog.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/RpcClient/Models/RpcApplicationLog.cs b/src/RpcClient/Models/RpcApplicationLog.cs index 038a7afff..456f432c1 100644 --- a/src/RpcClient/Models/RpcApplicationLog.cs +++ b/src/RpcClient/Models/RpcApplicationLog.cs @@ -20,6 +20,7 @@ public JObject ToJson() JObject json = new JObject(); json["txid"] = TxId?.ToString(); json["blockhash"] = BlockHash?.ToString(); + json["executions"] = Executions.Select(p => p.ToJson()).ToArray(); return json; } From d789fd71ff89ac09d1ac4c2207c11ee8270a9720 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=BF=97=E5=90=8C?= Date: Wed, 11 Nov 2020 20:15:31 +0800 Subject: [PATCH 6/9] Fixed UT --- src/RpcClient/Models/RpcApplicationLog.cs | 6 +- tests/Neo.Network.RPC.Tests/RpcTestCases.json | 220 +++++++++--------- 2 files changed, 116 insertions(+), 110 deletions(-) diff --git a/src/RpcClient/Models/RpcApplicationLog.cs b/src/RpcClient/Models/RpcApplicationLog.cs index 456f432c1..87fe0a82e 100644 --- a/src/RpcClient/Models/RpcApplicationLog.cs +++ b/src/RpcClient/Models/RpcApplicationLog.cs @@ -18,8 +18,10 @@ public class RpcApplicationLog public JObject ToJson() { JObject json = new JObject(); - json["txid"] = TxId?.ToString(); - json["blockhash"] = BlockHash?.ToString(); + if(TxId != null) + json["txid"] = TxId.ToString(); + if (BlockHash != null) + json["blockhash"] = BlockHash.ToString(); json["executions"] = Executions.Select(p => p.ToJson()).ToArray(); return json; } diff --git a/tests/Neo.Network.RPC.Tests/RpcTestCases.json b/tests/Neo.Network.RPC.Tests/RpcTestCases.json index b9e0bd15c..1b827e696 100644 --- a/tests/Neo.Network.RPC.Tests/RpcTestCases.json +++ b/tests/Neo.Network.RPC.Tests/RpcTestCases.json @@ -1209,145 +1209,149 @@ "id": "1", "result": { "txid": "0xe36f62923deb64376e5e982e19b60afc65faca8d9e8eb71ac12f7298ce32ef7b", - "trigger": "Application", - "vmstate": "HALT", - "gasconsumed": "5814860", - "stack": [ + "executions": [ { - "type": "Array", - "value": [ - { - "type": "Any" - }, - { - "type": "Integer", - "value": "1" - }, - { - "type": "Integer", - "value": "1223" - }, - { - "type": "ByteString", - "value": "dGVzdHFxd2FzZGFz" - }, - { - "type": "Buffer", - "value": "CAwiNQw=" - }, + "trigger": "Application", + "vmstate": "HALT", + "gasconsumed": "5814860", + "stack": [ { "type": "Array", "value": [ { - "type": "ByteString", - "value": "YWE=" + "type": "Any" }, { - "type": "ByteString", - "value": "YmI=" + "type": "Integer", + "value": "1" + }, + { + "type": "Integer", + "value": "1223" }, { "type": "ByteString", - "value": "Y2Mw" - } - ] - }, - { - "type": "Map", - "value": [ + "value": "dGVzdHFxd2FzZGFz" + }, { - "key": { - "type": "Integer", - "value": "2" - }, - "value": { - "type": "Integer", - "value": "12" - } + "type": "Buffer", + "value": "CAwiNQw=" }, { - "key": { - "type": "Integer", - "value": "0" - }, - "value": { - "type": "Integer", - "value": "24" - } + "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" + } + } + ] } ] } - ] - } - ], - "notifications": [ - { - "contract": "0xbfe215933f29b29dacf0e8383722a62974ac8aa6", - "eventname": "event_name", - "state": { - "type": "Array", - "value": [ - { + ], + "notifications": [ + { + "contract": "0xbfe215933f29b29dacf0e8383722a62974ac8aa6", + "eventname": "event_name", + "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": "Integer", + "value": "1" }, { - "type": "ByteString", - "value": "YmI=" + "type": "Integer", + "value": "1223" }, { "type": "ByteString", - "value": "Y2Mw" - } - ] - }, - { - "type": "Map", - "value": [ + "value": "dGVzdHFxd2FzZGFz" + }, { - "key": { - "type": "Integer", - "value": "2" - }, - "value": { - "type": "Integer", - "value": "12" - } + "type": "Buffer", + "value": "CAwiNQw=" }, { - "key": { - "type": "Integer", - "value": "0" - }, - "value": { - "type": "Integer", - "value": "24" - } + "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" + } + } + ] } ] } @@ -1355,8 +1359,8 @@ } ] } - ] - } + } + ] } ] } From 1801721aa020a3c7fe37709e2a230761ea45971e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=BF=97=E5=90=8C?= Date: Wed, 11 Nov 2020 20:23:32 +0800 Subject: [PATCH 7/9] ??? --- src/RpcClient/Models/RpcApplicationLog.cs | 2 +- tests/Neo.Network.RPC.Tests/RpcTestCases.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/RpcClient/Models/RpcApplicationLog.cs b/src/RpcClient/Models/RpcApplicationLog.cs index 87fe0a82e..cfdfbcc7e 100644 --- a/src/RpcClient/Models/RpcApplicationLog.cs +++ b/src/RpcClient/Models/RpcApplicationLog.cs @@ -18,7 +18,7 @@ public class RpcApplicationLog public JObject ToJson() { JObject json = new JObject(); - if(TxId != null) + if (TxId != null) json["txid"] = TxId.ToString(); if (BlockHash != null) json["blockhash"] = BlockHash.ToString(); diff --git a/tests/Neo.Network.RPC.Tests/RpcTestCases.json b/tests/Neo.Network.RPC.Tests/RpcTestCases.json index 1b827e696..0158f7f9b 100644 --- a/tests/Neo.Network.RPC.Tests/RpcTestCases.json +++ b/tests/Neo.Network.RPC.Tests/RpcTestCases.json @@ -666,7 +666,7 @@ "jsonrpc": "2.0", "id": 1, "result": { - "magic": 0, + "magic": 0, "tcpport": 20333, "wsport": 20334, "nonce": 592651621, From 29497e2ae1f212fd23e7f951b25f0d8cad6256ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=BF=97=E5=90=8C?= Date: Thu, 12 Nov 2020 10:56:30 +0800 Subject: [PATCH 8/9] update --- src/RpcClient/RpcClient.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/RpcClient/RpcClient.cs b/src/RpcClient/RpcClient.cs index ca43fc744..e63a3e649 100644 --- a/src/RpcClient/RpcClient.cs +++ b/src/RpcClient/RpcClient.cs @@ -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; @@ -543,6 +544,16 @@ public async Task GetApplicationLogAsync(string txHash) return RpcApplicationLog.FromJson(result); } + /// + /// 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. + /// + public async Task GetApplicationLogAsync(string txHash, TriggerType triggerType) + { + var result = await RpcSendAsync(GetRpcName(), txHash, triggerType).ConfigureAwait(false); + return RpcApplicationLog.FromJson(result); + } + /// /// Returns all the NEP-5 transaction information occurred in the specified address. /// This method is provided by the plugin RpcNep5Tracker. From 181356051eca59d1c405587bc64fd037031724bb Mon Sep 17 00:00:00 2001 From: superboyiii <573504781@qq.com> Date: Fri, 13 Nov 2020 16:06:17 +0800 Subject: [PATCH 9/9] UT --- tests/Neo.Network.RPC.Tests/RpcTestCases.json | 268 +++++++++--------- tests/Neo.Network.RPC.Tests/UT_RpcClient.cs | 9 + 2 files changed, 138 insertions(+), 139 deletions(-) diff --git a/tests/Neo.Network.RPC.Tests/RpcTestCases.json b/tests/Neo.Network.RPC.Tests/RpcTestCases.json index d73f7fbb7..5de1433b6 100644 --- a/tests/Neo.Network.RPC.Tests/RpcTestCases.json +++ b/tests/Neo.Network.RPC.Tests/RpcTestCases.json @@ -1201,161 +1201,151 @@ "Request": { "jsonrpc": "2.0", "method": "getapplicationlog", - "params": [ "0x183cd84359cd9f8b956afcd02403ec07361c1dba55f0800241b4ef2b28e88bbb" ], + "params": [ "0x6ea186fe714b8168ede3b78461db8945c06d867da649852352dbe7cbf1ba3724" ], "id": 1 }, "Response": { "jsonrpc": "2.0", - "id": "1", + "id": 1, "result": { - "txid": "0xe36f62923deb64376e5e982e19b60afc65faca8d9e8eb71ac12f7298ce32ef7b", + "blockhash": "0x6ea186fe714b8168ede3b78461db8945c06d867da649852352dbe7cbf1ba3724", "executions": [ { - "trigger": "Application", + "trigger": "OnPersist", "vmstate": "HALT", - "gasconsumed": "5814860", - "stack": [ + "gasconsumed": "2031260", + "stack": [], + "notifications": [ { - "type": "Array", - "value": [ - { - "type": "Any" - }, - { - "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" - } - } - ] - } - ] + "contract": "0x668e0c1f9d7b70a99dd9e06eadd4c784d641afbc", + "eventname": "Transfer", + "state": { + "type": "Array", + "value": [ + { + "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" + } + ] + } } - ], + ] + }, + { + "trigger": "PostPersist", + "vmstate": "HALT", + "gasconsumed": "2031260", + "stack": [], + "notifications": [ + { + "contract": "0x668e0c1f9d7b70a99dd9e06eadd4c784d641afbc", + "eventname": "Transfer", + "state": { + "type": "Array", + "value": [ + { + "type": "Any" + }, + { + "type": "ByteString", + "value": "z6LDQN4w1uEMToIZiPSxToNRPog=" + }, + { + "type": "Integer", + "value": "50000000" + } + ] + } + } + ] + } + ] + } + } + }, + { + "Name": "getapplicationlogasync_triggertype", + "Request": { + "jsonrpc": "2.0", + "method": "getapplicationlog", + "params": [ "0x6ea186fe714b8168ede3b78461db8945c06d867da649852352dbe7cbf1ba3724", "OnPersist" ], + "id": 1 + }, + "Response": { + "jsonrpc": "2.0", + "id": 1, + "result": { + "blockhash": "0x6ea186fe714b8168ede3b78461db8945c06d867da649852352dbe7cbf1ba3724", + "executions": [ + { + "trigger": "OnPersist", + "vmstate": "HALT", + "gasconsumed": "2031260", + "stack": [], "notifications": [ { - "contract": "0xbfe215933f29b29dacf0e8383722a62974ac8aa6", - "eventname": "event_name", + "contract": "0x668e0c1f9d7b70a99dd9e06eadd4c784d641afbc", + "eventname": "Transfer", + "state": { + "type": "Array", + "value": [ + { + "type": "ByteString", + "value": "CqOHtT6Wt5iaYxQxoFbdH0CgQvY=" + }, + { + "type": "Any" + }, + { + "type": "Integer", + "value": "18083410" + } + ] + } + }, + { + "contract": "0x668e0c1f9d7b70a99dd9e06eadd4c784d641afbc", + "eventname": "Transfer", "state": { "type": "Array", "value": [ { - "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": "Any" + }, + { + "type": "ByteString", + "value": "z6LDQN4w1uEMToIZiPSxToNRPog=" + }, + { + "type": "Integer", + "value": "1252390" } ] } diff --git a/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs b/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs index 4f0b398ca..b558ef201 100644 --- a/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs +++ b/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs @@ -6,6 +6,7 @@ using Neo.IO.Json; using Neo.Network.P2P.Payloads; using Neo.Network.RPC.Models; +using Neo.SmartContract; using System; using System.Linq; using System.Net; @@ -421,6 +422,14 @@ public async Task GetApplicationLogTest() Assert.AreEqual(test.Response.Result.ToString(), result.ToJson().ToString()); } + [TestMethod()] + public async Task GetApplicationLogTest_TriggerType() + { + var test = TestUtils.RpcTestCases.Find(p => p.Name == (nameof(rpc.GetApplicationLogAsync) + "_triggertype").ToLower()); + var result = await rpc.GetApplicationLogAsync(test.Request.Params[0].AsString(), TriggerType.OnPersist); + Assert.AreEqual(test.Response.Result.ToString(), result.ToJson().ToString()); + } + [TestMethod()] public async Task GetNep5TransfersTest() {