python – Failing to assemble transaction that unlocks P2WSH

0
88


I’m attempting to unlock the P2WSH output of the next transaction:

https://blockstream.data/testnet/tx/b435b180c936564cc902ce3d7011643836a74d671159d494f59536e70d977cd2

The script that I am paying to is a non-standard script, which could be unlocked by pushing OP_5 OP_0 earlier than analysis.

Here is the Python code I take advantage of to assemble the unlocking transaction:

from bitcoinutils.setup import setup
from bitcoinutils.utils import to_satoshis
from bitcoinutils.transactions import Transaction, TxInput, TxOutput
from bitcoinutils.keys import PrivateKey, P2wshAddress, P2wpkhAddress
from bitcoinutils.script import Script


def essential():
    # at all times bear in mind to setup the community
    setup('testnet')

    p2wsh_witness_script = Script.from_raw('0000018257615179547a75537a537a537a0079537a75527a527a7575615279008763537952795279615179517993517a75517a75619c77777777675279518763537952795279949c7777777767006868')

    fromAddress = P2wshAddress.from_script(p2wsh_witness_script)
    #print(fromAddress.to_string())

    toAddress = P2wpkhAddress.from_address("tb1qelplgcx5q7lj4mgk4sg8tlnq6njvamurvntwha")

    # set values
    txid = 'b435b180c936564cc902ce3d7011643836a74d671159d494f59536e70d977cd2'
    vout = 0
    quantity = 0.00001400
    payment = 0.00000200


    # create transaction enter from tx id of UTXO
    txin = TxInput(txid, vout)

    txOut1 = TxOutput(to_satoshis(quantity - payment), toAddress.to_script_pub_key())

    tx = Transaction([txin], [txOut1], has_segwit=True)

    tx.witnesses.append(Script(['OP_5', 'OP_0', p2wsh_witness_script.to_hex()]))

    # print uncooked signed transaction able to be broadcasted
    print("nRaw signed transaction:n" + tx.serialize())
    print("nTxId:", tx.get_txid())


if __name__ == "__main__":
    essential()

It produces the next serialized transaction:

02000000000101d27c970de73695f594d45911674da736386411703dce02c94c5636c980b135b40000000000ffffffff01b004000000000000160014cfc3f460d407bf2aed16ac1075fe60d4e4ceef83035500500000018257615179547a75537a537a537a0079537a75527a527a7575615279008763537952795279615179517993517a75517a75619c77777777675279518763537952795279949c777777776700686800000000

Sadly, whereas broadcasting, I get the next error:

sendrawtransaction RPC error: {"code":-22,"message":"TX decode failed. Be sure the tx has at the very least one enter."}

I’m not certain what I am lacking. Does the library serialize one thing incorrect? Is the redeeming script too giant?

LEAVE A REPLY

Please enter your comment!
Please enter your name here