Browse Source

interface.get_history: enforce sorted order of heights

related: #7058
patch-4
SomberNight 4 years ago
parent
commit
26d73cba0e
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 13
      electrum/interface.py

13
electrum/interface.py

@ -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]:

Loading…
Cancel
Save