From 948e4308464decc5a8e12ad8fb4321ea5f46e744 Mon Sep 17 00:00:00 2001 From: Erik van den Brink Date: Sun, 13 Jan 2019 17:10:07 +0100 Subject: [PATCH 1/2] Add undocumented gettransactionheight RPC method --- neo/api/JSONRPC/JsonRpcApi.py | 13 +++++++++++++ neo/api/JSONRPC/test_json_rpc_api.py | 23 +++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/neo/api/JSONRPC/JsonRpcApi.py b/neo/api/JSONRPC/JsonRpcApi.py index f4a3c012d..ea3cb74f0 100644 --- a/neo/api/JSONRPC/JsonRpcApi.py +++ b/neo/api/JSONRPC/JsonRpcApi.py @@ -271,6 +271,19 @@ def json_rpc_method_handler(self, method, params): return storage_item.Value.hex() return None + elif method == "gettransactionheight": + try: + hash = UInt256.ParseString(params[0]) + except Exception: + # throws exception, not anything more specific + raise JsonRpcError(-100, "Unknown transaction") + + tx, height = Blockchain.Default().GetTransaction(hash) + if tx: + return height + else: + raise JsonRpcError(-100, "Unknown transaction") + elif method == "gettxout": hash = params[0].encode('utf-8') index = params[1] diff --git a/neo/api/JSONRPC/test_json_rpc_api.py b/neo/api/JSONRPC/test_json_rpc_api.py index df32f4b43..b12c79c18 100644 --- a/neo/api/JSONRPC/test_json_rpc_api.py +++ b/neo/api/JSONRPC/test_json_rpc_api.py @@ -1692,3 +1692,26 @@ def test_getblockheader_non_verbose(self): blockheader = Helper.AsSerializableWithType(output, 'neo.Core.Header.Header') self.assertEqual(blockheader.Index, 11) self.assertEqual(str(blockheader.Hash), GetBlockchain().GetBlockHash(11).decode('utf8')) + + def test_gettransactionheight(self): + txid = 'f999c36145a41306c846ea80290416143e8e856559818065be3f4e143c60e43a' + req = self._gen_post_rpc_req("gettransactionheight", params=[txid]) + mock_req = mock_post_request(json.dumps(req).encode("utf-8")) + res = json.loads(self.app.home(mock_req)) + self.assertEqual(9448, res['result']) + + def test_gettransactionheight_invalid_hash(self): + txid = 'invalid_tx_id' + req = self._gen_post_rpc_req("gettransactionheight", params=[txid]) + mock_req = mock_post_request(json.dumps(req).encode("utf-8")) + res = json.loads(self.app.home(mock_req)) + self.assertTrue('error' in res) + self.assertEqual(res['error']['message'], 'Unknown transaction') + + def test_gettransactionheight_invalid_hash2(self): + txid = 'a' * 64 # something the right length but unknown + req = self._gen_post_rpc_req("gettransactionheight", params=[txid]) + mock_req = mock_post_request(json.dumps(req).encode("utf-8")) + res = json.loads(self.app.home(mock_req)) + self.assertTrue('error' in res) + self.assertEqual(res['error']['message'], 'Unknown transaction') From 42429d678ffe16f3b2eb62f9144555c638d49cce Mon Sep 17 00:00:00 2001 From: Erik van den Brink Date: Sun, 13 Jan 2019 17:12:52 +0100 Subject: [PATCH 2/2] add changelog --- CHANGELOG.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 30f9f26be..99114a578 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -31,6 +31,7 @@ All notable changes to this project are documented in this file. - Update TestNet seeds `#807 `_ - Add Reset logic to NodeLeader such that Blockchain fixture testcases reset properly `#809 `_ - Resolve peewee DeprecationWarning `#810 `_ +- Add gettransactionheight RPC method `#813 `_ [0.8.2] 2018-10-31