interface: check server response for some methods
some basic sanity checks Previously if the server sent back a malformed response, it could partially corrupt a wallet file. (as sometimes the response would get persisted, and issues would only arise later when the values were used)
This commit is contained in:
@@ -168,15 +168,12 @@ class Synchronizer(SynchronizerBase):
|
||||
self.requested_histories.add((addr, status))
|
||||
h = address_to_scripthash(addr)
|
||||
self._requests_sent += 1
|
||||
result = await self.network.get_history_for_scripthash(h)
|
||||
result = await self.interface.get_history_for_scripthash(h)
|
||||
self._requests_answered += 1
|
||||
self.logger.info(f"receiving history {addr} {len(result)}")
|
||||
hashes = set(map(lambda item: item['tx_hash'], result))
|
||||
hist = list(map(lambda item: (item['tx_hash'], item['height']), result))
|
||||
# tx_fees
|
||||
for item in result:
|
||||
if item['height'] in (-1, 0) and 'fee' not in item:
|
||||
raise Exception("server response to get_history contains unconfirmed tx without fee")
|
||||
tx_fees = [(item['tx_hash'], item.get('fee')) for item in result]
|
||||
tx_fees = dict(filter(lambda x:x[1] is not None, tx_fees))
|
||||
# Check that txids are unique
|
||||
@@ -214,7 +211,7 @@ class Synchronizer(SynchronizerBase):
|
||||
async def _get_transaction(self, tx_hash, *, allow_server_not_finding_tx=False):
|
||||
self._requests_sent += 1
|
||||
try:
|
||||
raw_tx = await self.network.get_transaction(tx_hash)
|
||||
raw_tx = await self.interface.get_transaction(tx_hash)
|
||||
except UntrustedServerReturnedError as e:
|
||||
# most likely, "No such mempool or blockchain transaction"
|
||||
if allow_server_not_finding_tx:
|
||||
|
||||
Reference in New Issue
Block a user