Trying to spend UTXO with custom script

To unlock, the locking script will require three numbers whose sum is 15 and maximum is smaller than 8. So I did this script in python, duplicating the top 3, then checking each of them whether less than 8, after removing them adding them up to check 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]

send it with this function 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 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 address 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 value (signature + public_key)
    txin.scriptSig = CScript([sig, my_public_key])

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

    # Broadcast the transaction
    return broadcast_transaction(tx)

It works for classic P2PKH, but when i use my txout_scriptpubkey, the response is

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

Any help is appreciated, I don't know where i did wrong in the script. I used 8 first but OP_8 needed to be used I suppose, but still doesn't work.



from Recent Questions - Bitcoin Stack Exchange https://ift.tt/wxWrOC8
via IFTTT

Popular posts from this blog

Future of Bitcoin encryption and security in a QC era

Possible rollback due to lazy reveal in BRC20?

A way to recover scammed Bitcoin investment