bitcoin core – Attempting to spend UTXO with customized script

0
12
bitcoin core – Attempting to spend UTXO with customized script


To unlock, the locking script would require three numbers whose sum is 15 and most is smaller than 8. So I did this script in python, duplicating the highest 3, then checking every of them whether or not lower than 8, after eradicating them including them as much as test if its 15.

ex2a_txout_scriptPubKey = [OP_3DUP,OP_8,OP_LESSTHAN,OP_VERIFY,OP_8,OP_LESSTHAN,OP_VERIFY,OP_8,OP_LESSTHAN,OP_VERIFY,OP_ADD,OP_ADD,OP_15,OP_EQUALVERIFY]

ship it with this operate response = send_from_P2PKH_transaction(amount_to_send, txid_to_spend, utxo_index, ex2a_txout_scriptPubKey)

def send_from_P2PKH_transaction(amount_to_send, txid_to_spend, utxo_index, txout_scriptPubKey):
    # Step 1: Create the txin
    txin = CMutableTxIn(COutPoint(lx(txid_to_spend), utxo_index)) #now we now have txin

    # Step 2: Create the txout
    txout = CMutableTxOut(amount_to_send * COIN, CScript(txout_scriptPubKey))

    # Step 3: Create the transaction
    tx = CMutableTransaction([txin], [txout])

    # Step 4: Create the txin_scriptPubKey (from the deal with holding the UTXO)
    txin_scriptPubKey = my_address.to_scriptPubKey()

    # Step 5: Create the signature
    sig = create_OP_CHECKSIG_signature(tx, txin_scriptPubKey, my_private_key)

    # Step 6: Set the txin's scriptSig worth (signature + public_key)
    txin.scriptSig = CScript([sig, my_public_key])

    # Confirm the transaction
    VerifyScript(txin.scriptSig, txin_scriptPubKey, tx, 0, (SCRIPT_VERIFY_P2SH,))

    # Broadcast the transaction
    return broadcast_transaction(tx)

It really works for traditional P2PKH, however when i take advantage of my txout_scriptpubkey, the response is

`400 Dangerous Request sendrawtransaction RPC error -26: scriptpubkey`

Any assistance is appreciated, I do not know the place i did fallacious within the script. I used 8 first however OP_8 wanted for use I suppose, however nonetheless would not work. EDIT: It additionally would not settle for "[OP_5, OP_EQUAL]". I can not make it settle for something apart from P2PKH.

LEAVE A REPLY

Please enter your comment!
Please enter your name here