mirror of
https://github.com/LBRYFoundation/lbry-sdk.git
synced 2025-09-01 17:55:13 +00:00
Merge pull request #2989 from lbryio/blocking-wallet-send
add `--blocking` to `account_send` and `wallet_send`
This commit is contained in:
commit
cf6a47ecb7
2 changed files with 29 additions and 21 deletions
|
@ -1459,7 +1459,7 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
@requires(WALLET_COMPONENT)
|
@requires(WALLET_COMPONENT)
|
||||||
async def jsonrpc_wallet_send(
|
async def jsonrpc_wallet_send(
|
||||||
self, amount, addresses, wallet_id=None,
|
self, amount, addresses, wallet_id=None,
|
||||||
change_account_id=None, funding_account_ids=None, preview=False):
|
change_account_id=None, funding_account_ids=None, preview=False, blocking=True):
|
||||||
"""
|
"""
|
||||||
Send the same number of credits to multiple addresses using all accounts in wallet to
|
Send the same number of credits to multiple addresses using all accounts in wallet to
|
||||||
fund the transaction and the default account to receive any change.
|
fund the transaction and the default account to receive any change.
|
||||||
|
@ -1467,12 +1467,14 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
Usage:
|
Usage:
|
||||||
wallet_send <amount> <addresses>... [--wallet_id=<wallet_id>] [--preview]
|
wallet_send <amount> <addresses>... [--wallet_id=<wallet_id>] [--preview]
|
||||||
[--change_account_id=None] [--funding_account_ids=<funding_account_ids>...]
|
[--change_account_id=None] [--funding_account_ids=<funding_account_ids>...]
|
||||||
|
[--blocking]
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
--wallet_id=<wallet_id> : (str) restrict operation to specific wallet
|
--wallet_id=<wallet_id> : (str) restrict operation to specific wallet
|
||||||
--change_account_id=<wallet_id> : (str) account where change will go
|
--change_account_id=<wallet_id> : (str) account where change will go
|
||||||
--funding_account_ids=<funding_account_ids> : (str) accounts to fund the transaction
|
--funding_account_ids=<funding_account_ids> : (str) accounts to fund the transaction
|
||||||
--preview : (bool) do not broadcast the transaction
|
--preview : (bool) do not broadcast the transaction
|
||||||
|
--blocking : (bool) wait until tx has synced
|
||||||
|
|
||||||
Returns: {Transaction}
|
Returns: {Transaction}
|
||||||
"""
|
"""
|
||||||
|
@ -1498,13 +1500,11 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
tx = await Transaction.create(
|
tx = await Transaction.create(
|
||||||
[], outputs, accounts, account
|
[], outputs, accounts, account
|
||||||
)
|
)
|
||||||
|
|
||||||
if not preview:
|
if not preview:
|
||||||
await self.ledger.broadcast(tx)
|
await self.broadcast_or_release(tx, blocking)
|
||||||
self.component_manager.loop.create_task(self.analytics_manager.send_credits_sent())
|
self.component_manager.loop.create_task(self.analytics_manager.send_credits_sent())
|
||||||
else:
|
else:
|
||||||
await self.ledger.release_tx(tx)
|
await self.ledger.release_tx(tx)
|
||||||
|
|
||||||
return tx
|
return tx
|
||||||
|
|
||||||
ACCOUNT_DOC = """
|
ACCOUNT_DOC = """
|
||||||
|
@ -1782,24 +1782,26 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
)
|
)
|
||||||
|
|
||||||
@requires(WALLET_COMPONENT)
|
@requires(WALLET_COMPONENT)
|
||||||
def jsonrpc_account_send(self, amount, addresses, account_id=None, wallet_id=None, preview=False):
|
def jsonrpc_account_send(self, amount, addresses, account_id=None, wallet_id=None, preview=False, blocking=False):
|
||||||
"""
|
"""
|
||||||
Send the same number of credits to multiple addresses from a specific account (or default account).
|
Send the same number of credits to multiple addresses from a specific account (or default account).
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
account_send <amount> <addresses>... [--account_id=<account_id>] [--wallet_id=<wallet_id>] [--preview]
|
account_send <amount> <addresses>... [--account_id=<account_id>] [--wallet_id=<wallet_id>] [--preview]
|
||||||
|
[--blocking]
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
--account_id=<account_id> : (str) account to fund the transaction
|
--account_id=<account_id> : (str) account to fund the transaction
|
||||||
--wallet_id=<wallet_id> : (str) restrict operation to specific wallet
|
--wallet_id=<wallet_id> : (str) restrict operation to specific wallet
|
||||||
--preview : (bool) do not broadcast the transaction
|
--preview : (bool) do not broadcast the transaction
|
||||||
|
--blocking : (bool) wait until tx has synced
|
||||||
|
|
||||||
Returns: {Transaction}
|
Returns: {Transaction}
|
||||||
"""
|
"""
|
||||||
return self.jsonrpc_wallet_send(
|
return self.jsonrpc_wallet_send(
|
||||||
amount=amount, addresses=addresses, wallet_id=wallet_id,
|
amount=amount, addresses=addresses, wallet_id=wallet_id,
|
||||||
change_account_id=account_id, funding_account_ids=[account_id] if account_id else [],
|
change_account_id=account_id, funding_account_ids=[account_id] if account_id else [],
|
||||||
preview=preview
|
preview=preview, blocking=blocking
|
||||||
)
|
)
|
||||||
|
|
||||||
SYNC_DOC = """
|
SYNC_DOC = """
|
||||||
|
|
|
@ -133,7 +133,7 @@ class Ledger(metaclass=LedgerRegistry):
|
||||||
self._on_transaction_controller = StreamController()
|
self._on_transaction_controller = StreamController()
|
||||||
self.on_transaction = self._on_transaction_controller.stream
|
self.on_transaction = self._on_transaction_controller.stream
|
||||||
self.on_transaction.listen(
|
self.on_transaction.listen(
|
||||||
lambda e: log.debug(
|
lambda e: log.info(
|
||||||
'(%s) on_transaction: address=%s, height=%s, is_verified=%s, tx.id=%s',
|
'(%s) on_transaction: address=%s, height=%s, is_verified=%s, tx.id=%s',
|
||||||
self.get_id(), e.address, e.tx.height, e.tx.is_verified, e.tx.id
|
self.get_id(), e.address, e.tx.height, e.tx.is_verified, e.tx.id
|
||||||
)
|
)
|
||||||
|
@ -682,20 +682,26 @@ class Ledger(metaclass=LedgerRegistry):
|
||||||
address_record['address']
|
address_record['address']
|
||||||
)) for address_record in records
|
)) for address_record in records
|
||||||
], timeout=1)
|
], timeout=1)
|
||||||
if pending:
|
if not pending:
|
||||||
records = await self.db.get_addresses(address__in=addresses)
|
return True
|
||||||
for record in records:
|
records = await self.db.get_addresses(address__in=addresses)
|
||||||
found = False
|
for record in records:
|
||||||
local_history = (await self.get_local_status_and_history(
|
local_history = (await self.get_local_status_and_history(
|
||||||
record['address'], history=record['history']
|
record['address'], history=record['history']
|
||||||
))[1] if record['history'] else []
|
))[1] if record['history'] else []
|
||||||
for txid, local_height in local_history:
|
for txid, local_height in local_history:
|
||||||
if txid == tx.id and local_height >= height:
|
if txid == tx.id:
|
||||||
found = True
|
if local_height >= height:
|
||||||
if not found:
|
return True
|
||||||
log.debug("timeout: %s, %s, %s", record['history'], addresses, tx.id)
|
log.warning(
|
||||||
|
"local history has higher height than remote for %s (%i vs %i)", txid,
|
||||||
|
local_height, height
|
||||||
|
)
|
||||||
return False
|
return False
|
||||||
return True
|
log.warning(
|
||||||
|
"local history does not contain %s, requested height %i", tx.id, height
|
||||||
|
)
|
||||||
|
return False
|
||||||
|
|
||||||
async def _inflate_outputs(
|
async def _inflate_outputs(
|
||||||
self, query, accounts,
|
self, query, accounts,
|
||||||
|
|
Loading…
Add table
Reference in a new issue