Browse Source

Merge JoinMarket-Org/joinmarket-clientserver#1201: Create un/freeze all command in wallet-tool freeze

d832d788d1 Create un/freeze all command in wallet-tool freeze (chris-belcher)

Pull request description:

  If a user has many UTXOs but wants to spend just one, they would have to freeze all the UTXOs one-by-one except for one, then after sending do the same again unfreezing all UTXOs one-by-one. This new command drastically speeds up this process.

ACKs for top commit:
  kristapsk:
    re-ACK d832d788d1

Tree-SHA512: 16c24de153a22d7025bcfb622ac7cba3ab3438c86d0d1cce07deb3b828f1463713ab8c8ee41694a55e7d5074dc2fd92359afb6424ea59d2c2ac905b9dfdfe7e3
master
Kristaps Kaupe 4 years ago
parent
commit
1940764731
No known key found for this signature in database
GPG Key ID: 33E472FE870C7E5D
  1. 33
      jmclient/jmclient/wallet_utils.py

33
jmclient/jmclient/wallet_utils.py

@ -8,7 +8,7 @@ from datetime import datetime, timedelta
from optparse import OptionParser from optparse import OptionParser
from numbers import Integral from numbers import Integral
from collections import Counter from collections import Counter
from itertools import islice from itertools import islice, chain
from jmclient import (get_network, WALLET_IMPLEMENTATIONS, Storage, podle, from jmclient import (get_network, WALLET_IMPLEMENTATIONS, Storage, podle,
jm_single, BitcoinCoreInterface, WalletError, BaseWallet, jm_single, BitcoinCoreInterface, WalletError, BaseWallet,
VolatileStorage, StoragePasswordError, is_segwit_mode, SegwitLegacyWallet, VolatileStorage, StoragePasswordError, is_segwit_mode, SegwitLegacyWallet,
@ -47,7 +47,7 @@ The method is one of the following:
(signmessage) Sign a message with the private key from an address in (signmessage) Sign a message with the private key from an address in
the wallet. Use with -H and specify an HD wallet path for the address. the wallet. Use with -H and specify an HD wallet path for the address.
(signpsbt) Sign PSBT with JoinMarket wallet. (signpsbt) Sign PSBT with JoinMarket wallet.
(freeze) Freeze or un-freeze a specific utxo. Specify mixdepth with -m. (freeze) Freeze or un-freeze UTXOs. Specify mixdepth with -m.
(gettimelockaddress) Obtain a timelocked address. Argument is locktime value as yyyy-mm. For example `2021-03`. (gettimelockaddress) Obtain a timelocked address. Argument is locktime value as yyyy-mm. For example `2021-03`.
(addtxoutproof) Add a tx out proof as metadata to a burner transaction. Specify path with (addtxoutproof) Add a tx out proof as metadata to a burner transaction. Specify path with
-H and proof which is output of Bitcoin Core\'s RPC call gettxoutproof. -H and proof which is output of Bitcoin Core\'s RPC call gettxoutproof.
@ -1177,15 +1177,15 @@ def display_utxos_for_disable_choice_default(wallet_service, utxos_enabled,
def default_user_choice(umax): def default_user_choice(umax):
jmprint("Choose an index 0 .. {} to freeze/unfreeze or " jmprint("Choose an index 0 .. {} to freeze/unfreeze or "
"-1 to just quit.".format(umax)) "-1 to just quit, or -2 to (un)freeze all".format(umax))
while True: while True:
try: try:
ret = int(input()) ret = int(input())
except ValueError: except ValueError:
jmprint("Invalid choice, must be an integer.", "error") jmprint("Invalid choice, must be an integer.", "error")
continue continue
if not isinstance(ret, int) or ret < -1 or ret > umax: if ret < -2 or ret > umax:
jmprint("Invalid choice, must be between: -1 and {}, " jmprint("Invalid choice, must be between: -2 and {}, "
"try again.".format(umax), "error") "try again.".format(umax), "error")
continue continue
break break
@ -1209,6 +1209,8 @@ def display_utxos_for_disable_choice_default(wallet_service, utxos_enabled,
chosen_idx = default_user_choice(max_id) chosen_idx = default_user_choice(max_id)
if chosen_idx == -1: if chosen_idx == -1:
return None return None
if chosen_idx == -2:
return "all"
# the return value 'disable' is the action we are going to take; # the return value 'disable' is the action we are going to take;
# so it should be true if the utxos is currently unfrozen/enabled. # so it should be true if the utxos is currently unfrozen/enabled.
disable = False if chosen_idx <= disabled_max else True disable = False if chosen_idx <= disabled_max else True
@ -1266,14 +1268,21 @@ def wallet_freezeutxo(wallet_service, md, display_callback=None, info_callback=N
utxos_enabled, utxos_disabled) utxos_enabled, utxos_disabled)
if display_ret is None: if display_ret is None:
break break
(txid, index), disable = display_ret if display_ret == "all":
wallet_service.disable_utxo(txid, index, disable) disable = (len(utxos_disabled) == 0)
if disable: info_callback("Setting all UTXOs to " + ("frozen" if disable else "unfrozen")
info_callback("Utxo: {} is now frozen and unavailable for spending." + " . . .")
.format(fmt_utxo((txid, index)))) for txid, index in chain(utxos_enabled, utxos_disabled):
wallet_service.disable_utxo(txid, index, disable)
else: else:
info_callback("Utxo: {} is now unfrozen and available for spending." (txid, index), disable = display_ret
.format(fmt_utxo((txid, index)))) wallet_service.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" return "Done"

Loading…
Cancel
Save