Browse Source

Merge #576: Display address for UTXO on wallet-tool.py freeze

6fa7f4cdbb Display address for UTXO on wallet-tool.py freeze (Kristaps Kaupe)

Pull request description:

  Suggested by @chris-belcher in #575. Also changes value output from `Y sats` to `X BTC (Y sat)` as in other places.

Top commit has no ACKs.

Tree-SHA512: 60747466f08b282edc9e3dacc6e038de82905e6364065c4b51a084a49832b0f430f92553bf6339db80005db55ca688b863a360e88cd99a6dbf3d5154344b09c3
master
Kristaps Kaupe 6 years ago
parent
commit
7706665b2e
No known key found for this signature in database
GPG Key ID: D47B1B4232B55437
  1. 24
      jmclient/jmclient/wallet_utils.py

24
jmclient/jmclient/wallet_utils.py

@ -933,7 +933,8 @@ def wallet_signmessage(wallet, hdpath, message):
retval = "Signature: {}\nTo verify this in Bitcoin Core".format(sig)
return retval + " use the RPC command 'verifymessage'"
def display_utxos_for_disable_choice_default(utxos_enabled, utxos_disabled):
def display_utxos_for_disable_choice_default(wallet_service, utxos_enabled,
utxos_disabled):
""" CLI implementation of the callback required as described in
wallet_disableutxo
"""
@ -957,8 +958,10 @@ def display_utxos_for_disable_choice_default(utxos_enabled, utxos_disabled):
def output_utxos(utxos, status, start=0):
for (txid, idx), v in utxos.items():
value = v['value']
jmprint("{:4}: {:68}: {} sats, -- {}".format(
start, fmt_utxo((txid, idx)), value, status))
jmprint("{:4}: {} ({}): {} -- {}".format(
start, fmt_utxo((txid, idx)),
wallet_service.wallet.script_to_addr(v["script"]),
btc.amount_to_str(value), status))
start += 1
yield txid, idx
@ -986,7 +989,7 @@ def get_utxos_enabled_disabled(wallet_service, md):
utxos_disabled[u] = utxos_all[u]
return utxos_enabled, utxos_disabled
def wallet_freezeutxo(wallet, md, display_callback=None, info_callback=None):
def wallet_freezeutxo(wallet_service, md, display_callback=None, info_callback=None):
""" Given a wallet and a mixdepth, display to the user
the set of available utxos, indexed by integer, and accept a choice
of index to "freeze", then commit this disabling to the wallet storage,
@ -997,8 +1000,9 @@ def wallet_freezeutxo(wallet, md, display_callback=None, info_callback=None):
** display_callback signature:
args:
1. utxos_enabled ; dict of utxos as format in wallet.py.
2. utxos_disabled ; as above, for disabled
1. wallet_service
2. utxos_enabled ; dict of utxos as format in wallet.py.
3. utxos_disabled ; as above, for disabled
returns:
1.((txid(str), index(int)), disabled(bool)) of chosen utxo
for freezing/unfreezing, or None for no action/cancel.
@ -1016,16 +1020,18 @@ def wallet_freezeutxo(wallet, md, display_callback=None, info_callback=None):
info_callback("Specify the mixdepth with the -m flag", "error")
return "Failed"
while True:
utxos_enabled, utxos_disabled = get_utxos_enabled_disabled(wallet, md)
utxos_enabled, utxos_disabled = get_utxos_enabled_disabled(
wallet_service, md)
if utxos_disabled == {} and utxos_enabled == {}:
info_callback("The mixdepth: " + str(md) + \
" contains no utxos to freeze/unfreeze.", "error")
return "Failed"
display_ret = display_callback(utxos_enabled, utxos_disabled)
display_ret = display_callback(wallet_service,
utxos_enabled, utxos_disabled)
if display_ret is None:
break
(txid, index), disable = display_ret
wallet.disable_utxo(txid, index, disable)
wallet_service.disable_utxo(txid, index, disable)
if disable:
info_callback("Utxo: {} is now frozen and unavailable for spending."
.format(fmt_utxo((txid, index))))

Loading…
Cancel
Save