Skip to content

Commit

Permalink
Add gettransactionheight RPC method (CityOfZion#813)
Browse files Browse the repository at this point in the history
* Add undocumented gettransactionheight RPC method

* add changelog
  • Loading branch information
ixje authored and jseagrave21 committed Jan 25, 2019
1 parent 66e0320 commit 246f4e6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ All notable changes to this project are documented in this file.
- Add Reset logic to NodeLeader such that Blockchain fixture testcases reset properly `#809 <https://github.com/CityOfZion/neo-python/pull/809>`_
- Resolve peewee DeprecationWarning `#810 <https://github.com/CityOfZion/neo-python/pull/810>`_
- Add VM SafeReadBytes `#812 <https://github.com/CityOfZion/neo-python/pull/812>`_
- Add gettransactionheight RPC method `#813 <https://github.com/CityOfZion/neo-python/pull/813>`_
- Update ``ApplicationEngine`` methods ``CheckStackSize`` and ``GetPrice`` `#814 <https://github.com/CityOfZion/neo-python/pull/814/>`_


Expand Down
13 changes: 13 additions & 0 deletions neo/api/JSONRPC/JsonRpcApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
23 changes: 23 additions & 0 deletions neo/api/JSONRPC/test_json_rpc_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

0 comments on commit 246f4e6

Please sign in to comment.