From db71d30b80380fed44e331e288ee4020df02035c Mon Sep 17 00:00:00 2001 From: Adam Gibson Date: Sat, 7 Jan 2023 13:55:18 +0000 Subject: [PATCH] address review of @PulpCattel --- jmbitcoin/jmbitcoin/secp256k1_transaction.py | 10 ++++------ jmclient/jmclient/taker_utils.py | 8 ++++---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/jmbitcoin/jmbitcoin/secp256k1_transaction.py b/jmbitcoin/jmbitcoin/secp256k1_transaction.py index c0b3c41..1d61d25 100644 --- a/jmbitcoin/jmbitcoin/secp256k1_transaction.py +++ b/jmbitcoin/jmbitcoin/secp256k1_transaction.py @@ -106,13 +106,13 @@ def human_readable_output(txoutput): pass # non standard script return outdict -def there_is_one_segwit_input(x): +def there_is_one_segwit_input(input_types): # note that we need separate input types for # any distinct types of scripthash inputs supported, # since each may have a different size of witness; in # that case, the internal list in this list comprehension # will need updating. - return any([y in ["p2sh-p2wpkh", "p2wpkh", "p2wsh"] for y in x]) + return any(y in ["p2sh-p2wpkh", "p2wpkh", "p2wsh"] for y in input_types) def estimate_tx_size(ins, outs): '''Estimate transaction size. @@ -174,16 +174,14 @@ def estimate_tx_size(ins, outs): for i in ins: if i not in inmults: raise NotImplementedError( - "Script type not supported for transaction size " - "estimation: {}".format(i)) + f"Script type not supported for transaction size estimation: {i}") inmult = inmults[i] nwsize += inmult["nw"] wsize += inmult["w"] for o in outs: if o not in outmults: raise NotImplementedError( - "Script type not supported for transaction size " - "estimation: {}".format(o)) + f"Script type not supported for transaction size estimation: {o}") nwsize += outmults[o] if not tx_is_segwit: diff --git a/jmclient/jmclient/taker_utils.py b/jmclient/jmclient/taker_utils.py index 97e4547..c166d00 100644 --- a/jmclient/jmclient/taker_utils.py +++ b/jmclient/jmclient/taker_utils.py @@ -26,8 +26,8 @@ def get_utxo_scripts(wallet: BaseWallet, utxos): # as passed from `get_utxos_by_mixdepth` at one mixdepth, # return the list of script types for each utxo script_types = [] - for k, v in utxos.items(): - script_types.append(wallet.get_outtype(v["address"])) + for utxo in utxos.values(): + script_types.append(wallet.get_outtype(utxo["address"])) return script_types def direct_send(wallet_service, amount, mixdepth, destination, answeryes=False, @@ -110,13 +110,13 @@ def direct_send(wallet_service, amount, mixdepth, destination, answeryes=False, fee_est = estimate_tx_fee(len(utxos), 1, txtype=script_types, outtype=outtype) outs = [{"address": destination, "value": total_inputs_val - fee_est}] else: - change_type = wallet_service.get_txtype() + change_type = txtype if custom_change_addr: change_type = wallet_service.get_outtype(custom_change_addr) if change_type is None: # we don't recognize this type; best we can do is revert to default, # even though it may be inaccurate: - change_type = wallet_service.get_txtype() + change_type = txtype outtypes = [change_type, outtype] # not doing a sweep; we will have change. # 8 inputs to be conservative; note we cannot account for the possibility