Support "latest" tag in eth_getBlockByNumber

Fixes #140
This commit is contained in:
Hendrik Hofstadt 2021-08-17 16:24:22 +02:00
parent 051e5d23b5
commit 9b6babbc4b
1 changed files with 6 additions and 2 deletions

View File

@ -123,8 +123,12 @@ class EthereumModel:
tag - integer of a block number, or the string "earliest", "latest" or "pending", as in the default block parameter.
full - If true it returns the full transaction objects, if false only the hashes of the transactions.
"""
if tag in ('earliest', 'latest', 'pending'): raise Exception("Invalid tag {}".format(tag))
number = int(tag, 16)
if tag == "latest":
number = int(self.client.get_slot()["result"])
elif tag in ('earliest', 'pending'):
raise Exception("Invalid tag {}".format(tag))
else:
number = int(tag, 16)
response = self.client.get_confirmed_block(number)
if 'error' in response:
raise Exception(response['error']['message'])