From 36eebbcd3d2b51e00afeb4a7fe8a2b50b3f6392e Mon Sep 17 00:00:00 2001 From: scgbckbone Date: Wed, 23 Apr 2025 15:41:35 +0200 Subject: [PATCH] segwit and wrapped are SS cmds only --- README.md | 4 ++-- psbt_faker/__init__.py | 9 ++++----- psbt_faker/txn.py | 14 +++++++------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 3971042..ef5b9da 100644 --- a/README.md +++ b/README.md @@ -36,8 +36,8 @@ Options: num-outs -f, --fee INTEGER Miner's fee in Satoshis -2, --psbt2 Make PSBTv2 - -s, --segwit Make inputs be segwit style - -w, --wrapped Make inputs be wrapped segwit style + -s, --segwit [SS] Make inputs be segwit style + -w, --wrapped [SS] Make inputs be wrapped segwit style (requires --segwit flag) -a, --styles [p2wsh|p2sh|p2sh-p2wsh|p2wsh-p2sh|p2wpkh|p2pkh|p2wpkh-p2sh|p2sh-p2wpkh|p2tr] Output address style (multiple ok). If diff --git a/psbt_faker/__init__.py b/psbt_faker/__init__.py index 7a2d8e8..1f58079 100755 --- a/psbt_faker/__init__.py +++ b/psbt_faker/__init__.py @@ -28,8 +28,8 @@ SIM_XPUB = 'tpubD6NzVbkrYhZ4XzL5Dhayo67Gorv1YMS7j8pRUvVMd5odC2LBPLAygka9p7748JtS @click.option('--num-change', '-c', help="Number of change outputs (default 1) from num-outs", default=1) @click.option('--fee', '-f', help="Miner's fee in Satoshis", default=1000) @click.option('--psbt2', '-2', help="Make PSBTv2", is_flag=True, default=False) -@click.option('--segwit', '-s', help="Make inputs be segwit style", is_flag=True, default=False) -@click.option('--wrapped', '-w', help="Make inputs be wrapped segwit style (requires --segwit flag)", is_flag=True, default=False) +@click.option('--segwit', '-s', help="[SS] Make inputs be segwit style", is_flag=True, default=False) +@click.option('--wrapped', '-w', help="[SS] Make inputs be wrapped segwit style (requires --segwit flag)", is_flag=True, default=False) @click.option('--styles', '-a', help="Output address style (multiple ok). If multisig only applies to non-change addresses.", multiple=True, default=None, type=click.Choice(ADDR_STYLES)) @click.option('--base64', '-6', help="Output base64 (default binary)", is_flag=True, default=False) @click.option('--testnet', '-t', help="Assume testnet4 addresses (default mainnet)", is_flag=True, default=False) @@ -58,9 +58,8 @@ def main(num_ins, num_change, num_outs, out_psbt, testnet, xpub, segwit, fee, st name, af, keys, M, N = from_simple_text(ms_config.split("\n")) psbt, outs = fake_ms_txn(num_ins, num_outs, M, keys, fee=fee, locktime=locktime, change_outputs=list(range(num_change)), outstyles=styles, - segwit_in=segwit, input_amount=input_amount, psbt_v2=psbt2, - incl_xpubs=incl_xpubs, wrapped=wrapped, is_testnet=testnet, - change_af=af) + input_amount=input_amount, psbt_v2=psbt2, change_af=af, + incl_xpubs=incl_xpubs, is_testnet=testnet) else: if zero_xfp: xpub = None diff --git a/psbt_faker/txn.py b/psbt_faker/txn.py index cf327c6..64a5fb2 100644 --- a/psbt_faker/txn.py +++ b/psbt_faker/txn.py @@ -354,9 +354,9 @@ def make_ms_address(M, keys, idx, is_change, addr_fmt="p2wsh", testnet=1, bip67= return addr, scriptPubKey, script, bip32paths -def fake_ms_txn(num_ins, num_outs, M, keys, fee=10000, outvals=None, segwit_in=True, - outstyles=['p2wsh'], change_outputs=[], incl_xpubs=False, psbt_v2=False, - input_amount=1E8, bip67=True, locktime=0, wrapped=False, +def fake_ms_txn(num_ins, num_outs, M, keys, fee=10000, outvals=None, + outstyles=['p2wsh'], change_outputs=[], incl_xpubs=False, + input_amount=1E8, bip67=True, locktime=0, psbt_v2=False, sequences=None, is_testnet=False, change_af=None): # make various size MULTISIG txn's ... completely fake and pointless values # - but has UTXO's to match needs @@ -392,10 +392,10 @@ def fake_ms_txn(num_ins, num_outs, M, keys, fee=10000, outvals=None, segwit_in=T addr, scriptPubKey, script, details = make_ms_address(M, keys, i, True, addr_fmt=change_af, bip67=bip67) - # lots of supporting details needed for p2sh inputs - if segwit_in: + if "p2wsh" in change_af: psbt.inputs[i].witness_script = script - else: + + if "p2sh" in change_af: psbt.inputs[i].redeem_script = script for pubkey, xfp_path in details: @@ -412,7 +412,7 @@ def fake_ms_txn(num_ins, num_outs, M, keys, fee=10000, outvals=None, segwit_in=T supply.vout.append(CTxOut(int(input_amount), scriptPubKey)) - if not segwit_in: + if "wsh" in change_af: psbt.inputs[i].utxo = supply.serialize_with_witness() else: psbt.inputs[i].witness_utxo = supply.vout[-1].serialize()