python – Native P2WSH over P2SH | P2SH-P2WSH

0
59


I am within the technique of making an attempt to generate a transaction utilizing the Python Bitcoin Utils library. that entails P2WSH-over-P2SH (P2SH-P2WSH). My exercise is on the regtest community. Under is the code snippet and deal with that I’ve ready.

txin_redeemScript = Script([
    'OP_2',
    private_key1.get_public_key().to_hex(),
    private_key2.get_public_key().to_hex(),
    'OP_2',
    'OP_CHECKMULTISIG'
])
script_bytes = txin_redeemScript.to_bytes()
hashsha256 = hashlib.sha256(script_bytes).digest()
hashsha256 = hexlify(hashsha256).decode('utf-8')

txin_scriptPubKey = Script(['OP_0', hashsha256])
txin_p2wsh_address = P2shAddress.from_script(txin_scriptPubKey)

This deal with is the place I intend to ship the cash, and that is the transaction I am forming:

p2pkh_addr = P2pkhAddress('n4bkvTyU1dVdzsrhWBqBw8fEMbHjJvtmJR')
txout = TxOutput(to_satoshis(amount_to_send), p2pkh_addr.to_script_pub_key())
tx = Transaction(inputs=p2sh_utxo, outputs=[txout], has_segwit=False)

That is the transaction and uncooked transaction ID

[{'address': '2N4vHiXTCCVMt4TYimTGXRCySzNLXkdiPyH', 'category': 'send', 'amount': Decimal('-0.10000000'), 'vout': 1, 'fee': Decimal('-0.00001430'), 'confirmations': 0, 'trusted': True, 'txid': 'f5f9c98b0c7b0731cba11f5a1b0494a62d2a2de5c09aaf3ac37fa56d48c271bd', 'wtxid': 'bed63897ca9c23ee891a9752b143ee063bf9aa97c813c5a455210a5f8437be6a', 'walletconflicts': [], 'time': 1693271904, 'timereceived': 1693271904, 'bip125-replaceable': 'sure', 'deserted': False}]

0200000001bd71c2486da57fc33aaf9ac0e52d2a2da694041b5a1fa1cb31077b0c8bc9f9f50100000000ffffffff015f5d9800000000001976a914fd337ad3bf81e086d96a68e1f8d6a0a510f8c24a88ac00000000

The next code is utilized to signal the transaction:

for tx_idx, txin in enumerate(p2sh_utxo):
    sig1 = sk1.sign_input(tx, tx_idx, txin_redeemScript)
    sig2 = sk2.sign_input(tx, tx_idx, txin_redeemScript)
    unlocking_script = Script(['OP_0', txin_redeemScript.to_hex()])
    txin.script_sig = unlocking_script

    witness_data = [b'','OP_0', sig1, sig2]
    tx.witnesses.append(TxWitnessInput(witness_data))

The mempool acceptance check is failing with the error 'reject-reason': 'mandatory-script-verify-flag-failed (Script evaluated with out error however completed with a false/empty prime stack aspect)'}

My familiarity with bitcoin programming is restricted, and I have been unable to find any pattern code or references regarding P2WSH over P2SH. Regardless of looking out varied on-line sources, I’ve but to seek out any explanations on how the spending course of operates. Any assist could be appreciated.

LEAVE A REPLY

Please enter your comment!
Please enter your name here