ledger.wait() accept timeout argument

This commit is contained in:
Lex Berezhny 2019-06-10 01:28:51 -04:00
parent 03e48c0968
commit 35cd42bfea

View file

@ -502,7 +502,7 @@ class BaseLedger(metaclass=LedgerRegistry):
def broadcast(self, tx): def broadcast(self, tx):
return self.network.broadcast(hexlify(tx.raw).decode()) return self.network.broadcast(hexlify(tx.raw).decode())
async def wait(self, tx: basetransaction.BaseTransaction, height=-1): async def wait(self, tx: basetransaction.BaseTransaction, height=-1, timeout=None):
addresses = set() addresses = set()
for txi in tx.inputs: for txi in tx.inputs:
if txi.txo_ref.txo is not None: if txi.txo_ref.txo is not None:
@ -514,9 +514,11 @@ class BaseLedger(metaclass=LedgerRegistry):
self.hash160_to_address(txo.script.values['pubkey_hash']) self.hash160_to_address(txo.script.values['pubkey_hash'])
) )
records = await self.db.get_addresses(cols=('address',), address__in=addresses) records = await self.db.get_addresses(cols=('address',), address__in=addresses)
await asyncio.wait([ done, pending = await asyncio.wait([
self.on_transaction.where(partial( self.on_transaction.where(partial(
lambda a, e: a == e.address and e.tx.height >= height and e.tx.id == tx.id, lambda a, e: a == e.address and e.tx.height >= height and e.tx.id == tx.id,
address_record['address'] address_record['address']
)) for address_record in records )) for address_record in records
]) ], timeout=timeout)
if pending:
raise TimeoutError('Timed out waiting for transaction.')