added utxo_release command

This commit is contained in:
Lex Berezhny 2019-01-04 02:49:29 -05:00
parent 20dd1e55f5
commit e65e1fb5a2
4 changed files with 42 additions and 0 deletions

View file

@ -2768,6 +2768,26 @@ class Daemon(AuthJSONRPCServer):
page, page_size page, page_size
) )
@requires(WALLET_COMPONENT)
def jsonrpc_utxo_release(self, account_id=None):
"""
When spending a UTXO it is locally locked to prevent double spends;
occasionally this can result in a UTXO being locked which ultimately
did not get spent (failed to broadcast, spend transaction was not
accepted by blockchain node, etc). This command releases the lock
on all UTXOs in your account.
Usage:
utxo_release [<account_id> | --account_id=<account_id>]
Options:
--account_id=<account_id> : (str) id of the account to query
Returns:
None
"""
return self.get_account_or_default(account_id).release_all_outputs()
@requires(WALLET_COMPONENT) @requires(WALLET_COMPONENT)
def jsonrpc_block_show(self, blockhash=None, height=None): def jsonrpc_block_show(self, blockhash=None, height=None):
""" """

View file

@ -236,3 +236,6 @@ class Account(BaseAccount):
) )
return tx return tx
async def release_all_outputs(self):
await self.ledger.db.release_all_outputs(self)

View file

@ -117,3 +117,11 @@ class WalletDatabase(BaseDatabase):
channel.private_key = private_key channel.private_key = private_key
certificates.append(channel) certificates.append(channel)
return certificates return certificates
async def release_all_outputs(self, account):
await self.db.execute(
"UPDATE txo SET is_reserved = 0 WHERE"
" is_reserved = 1 AND txo.address IN ("
" SELECT address from pubkey_address WHERE account = ?"
" )", [account.public_key.address]
)

View file

@ -846,3 +846,14 @@ class TransactionCommandsTestCase(CommandTestCase):
# inexistent # inexistent
result = await self.daemon.jsonrpc_transaction_show('0'*64) result = await self.daemon.jsonrpc_transaction_show('0'*64)
self.assertFalse(result['success']) self.assertFalse(result['success'])
async def test_utxo_release(self):
sendtxid = await self.blockchain.send_to_address(
await self.account.receiving.get_or_create_usable_address(), 1
)
await self.confirm_tx(sendtxid)
await self.assertBalance(self.account, '11.0')
await self.ledger.reserve_outputs(await self.account.get_utxos())
await self.assertBalance(self.account, '0.0')
await self.daemon.jsonrpc_utxo_release()
await self.assertBalance(self.account, '11.0')