From 66823aacd130b4d9a2048ff7fa32023df8716083 Mon Sep 17 00:00:00 2001 From: chris-belcher Date: Fri, 10 Jan 2020 12:46:25 +0000 Subject: [PATCH] Add loop in the CLI for freezing UTXOs Prior to this commit the wallet-tool (un)freeze tool would only allow a single freeze or unfreeze per run. So a user intending to (un)freeze several UTXOs would have to run the script several times which would be slow due to the need to sync the wallet many times. See also the discussion in: http://gnusha.org/joinmarket/2020-01-09.log --- jmclient/jmclient/wallet_utils.py | 34 ++++++++++++++++--------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/jmclient/jmclient/wallet_utils.py b/jmclient/jmclient/wallet_utils.py index efe5cfc..c009540 100644 --- a/jmclient/jmclient/wallet_utils.py +++ b/jmclient/jmclient/wallet_utils.py @@ -980,6 +980,7 @@ def display_utxos_for_disable_choice_default(utxos_enabled, utxos_disabled): start += 1 yield txid, idx + jmprint("List of UTXOs:") ulist = list(output_utxos(utxos_disabled, 'FROZEN')) disabled_max = len(ulist) - 1 ulist.extend(output_utxos(utxos_enabled, 'NOT FROZEN', start=len(ulist))) @@ -1032,22 +1033,23 @@ def wallet_freezeutxo(wallet, md, display_callback=None, info_callback=None): if md is None: info_callback("Specify the mixdepth with the -m flag", "error") return "Failed" - utxos_enabled, utxos_disabled = get_utxos_enabled_disabled(wallet, 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) - if display_ret is None: - return "OK" - (txid, index), disable = display_ret - wallet.disable_utxo(txid, index, disable) - if disable: - info_callback("Utxo: {} is now frozen and unavailable for spending." - .format(fmt_utxo((txid, index)))) - else: - info_callback("Utxo: {} is now unfrozen and available for spending." - .format(fmt_utxo((txid, index)))) + while True: + utxos_enabled, utxos_disabled = get_utxos_enabled_disabled(wallet, 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) + if display_ret is None: + break + (txid, index), disable = display_ret + wallet.disable_utxo(txid, index, disable) + if disable: + info_callback("Utxo: {} is now frozen and unavailable for spending." + .format(fmt_utxo((txid, index)))) + else: + info_callback("Utxo: {} is now unfrozen and available for spending." + .format(fmt_utxo((txid, index)))) return "Done" def get_wallet_type():