mirror of
https://github.com/LBRYFoundation/lbry-sdk.git
synced 2025-09-02 02:05:14 +00:00
ledger.wait() accept timeout argument
This commit is contained in:
parent
03e48c0968
commit
35cd42bfea
1 changed files with 5 additions and 3 deletions
|
@ -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.')
|
||||||
|
|
Loading…
Add table
Reference in a new issue