1
0

interface.get_history: enforce sorted order of heights

related: #7058
This commit is contained in:
SomberNight
2021-02-23 02:13:16 +01:00
parent 99845942e5
commit 26d73cba0e

View File

@@ -938,14 +938,21 @@ class Interface(Logger):
res = await self.session.send_request('blockchain.scripthash.get_history', [sh])
# check response
assert_list_or_tuple(res)
prev_height = 1
for tx_item in res:
assert_dict_contains_field(tx_item, field_name='height')
height = assert_dict_contains_field(tx_item, field_name='height')
assert_dict_contains_field(tx_item, field_name='tx_hash')
assert_integer(tx_item['height'])
assert_integer(height)
assert_hash256_str(tx_item['tx_hash'])
if tx_item['height'] in (-1, 0):
if height in (-1, 0):
assert_dict_contains_field(tx_item, field_name='fee')
assert_non_negative_integer(tx_item['fee'])
prev_height = - float("inf") # this ensures confirmed txs can't follow mempool txs
else:
# check monotonicity of heights
if height < prev_height:
raise RequestCorrupted(f'heights of confirmed txs must be in increasing order')
prev_height = height
return res
async def listunspent_for_scripthash(self, sh: str) -> List[dict]: