From a93914cc0340881f322dde28592372302c815802 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vitor=20Naz=C3=A1rio=20Coelho?= Date: Thu, 10 Jan 2019 17:03:24 -0200 Subject: [PATCH 1/4] getrawtransactionheight Nowadays two calls are need to get a transaction height, `getrawtransaction` with `verbose` and then use the `blockhash`. Other option is to use `confirmations`, but it can be misleading. --- neo/Network/RPC/RpcServer.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/neo/Network/RPC/RpcServer.cs b/neo/Network/RPC/RpcServer.cs index 5bf4b21f8d..186bd4f882 100644 --- a/neo/Network/RPC/RpcServer.cs +++ b/neo/Network/RPC/RpcServer.cs @@ -320,6 +320,19 @@ private JObject Process(string method, JArray _params) } return tx.ToArray().ToHexString(); } + case "getrawtransactionheight": + { + UInt256 hash = UInt256.Parse(_params[0].AsString()); + Transaction tx = Blockchain.Singleton.GetTransaction(hash); + if (tx == null) + throw new RpcException(-100, "Unknown transaction"); + + uint? height = Blockchain.Singleton.Store.GetTransactions().TryGet(hash)?.BlockIndex; + if (height != null) + return header.Index; + + throw new RpcException(-32603, "Invalid height"); + } case "getstorage": { UInt160 script_hash = UInt160.Parse(_params[0].AsString()); From 992651fd8b39c5c93d0f6b0ece747cb7e7c8d737 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vitor=20Naz=C3=A1rio=20Coelho?= Date: Thu, 10 Jan 2019 17:09:24 -0200 Subject: [PATCH 2/4] Minnor fix --- neo/Network/RPC/RpcServer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neo/Network/RPC/RpcServer.cs b/neo/Network/RPC/RpcServer.cs index 186bd4f882..416afa3353 100644 --- a/neo/Network/RPC/RpcServer.cs +++ b/neo/Network/RPC/RpcServer.cs @@ -329,7 +329,7 @@ private JObject Process(string method, JArray _params) uint? height = Blockchain.Singleton.Store.GetTransactions().TryGet(hash)?.BlockIndex; if (height != null) - return header.Index; + return height; throw new RpcException(-32603, "Invalid height"); } From d776b15264441165d8f961559bfa3688e2736587 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vitor=20Naz=C3=A1rio=20Coelho?= Date: Thu, 10 Jan 2019 17:15:39 -0200 Subject: [PATCH 3/4] Shargon's tip --- neo/Network/RPC/RpcServer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neo/Network/RPC/RpcServer.cs b/neo/Network/RPC/RpcServer.cs index 416afa3353..bc4ce9b0d9 100644 --- a/neo/Network/RPC/RpcServer.cs +++ b/neo/Network/RPC/RpcServer.cs @@ -320,7 +320,7 @@ private JObject Process(string method, JArray _params) } return tx.ToArray().ToHexString(); } - case "getrawtransactionheight": + case "gettransactionheight": { UInt256 hash = UInt256.Parse(_params[0].AsString()); Transaction tx = Blockchain.Singleton.GetTransaction(hash); From 576ed04fcef78f9c080353e7a2978211ba98defd Mon Sep 17 00:00:00 2001 From: erikzhang Date: Fri, 11 Jan 2019 16:07:23 +0800 Subject: [PATCH 4/4] modified --- neo/Network/RPC/RpcServer.cs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/neo/Network/RPC/RpcServer.cs b/neo/Network/RPC/RpcServer.cs index bc4ce9b0d9..f02cbbe922 100644 --- a/neo/Network/RPC/RpcServer.cs +++ b/neo/Network/RPC/RpcServer.cs @@ -320,19 +320,6 @@ private JObject Process(string method, JArray _params) } return tx.ToArray().ToHexString(); } - case "gettransactionheight": - { - UInt256 hash = UInt256.Parse(_params[0].AsString()); - Transaction tx = Blockchain.Singleton.GetTransaction(hash); - if (tx == null) - throw new RpcException(-100, "Unknown transaction"); - - uint? height = Blockchain.Singleton.Store.GetTransactions().TryGet(hash)?.BlockIndex; - if (height != null) - return height; - - throw new RpcException(-32603, "Invalid height"); - } case "getstorage": { UInt160 script_hash = UInt160.Parse(_params[0].AsString()); @@ -344,6 +331,13 @@ private JObject Process(string method, JArray _params) }) ?? new StorageItem(); return item.Value?.ToHexString(); } + case "gettransactionheight": + { + UInt256 hash = UInt256.Parse(_params[0].AsString()); + uint? height = Blockchain.Singleton.Store.GetTransactions().TryGet(hash)?.BlockIndex; + if (height.HasValue) return height.Value; + throw new RpcException(-100, "Unknown transaction"); + } case "gettxout": { UInt256 hash = UInt256.Parse(_params[0].AsString());