To unlock, the lock script requires three numbers with a total of 15 and a maximum of less than 8. So, after replicating this script in Python, replicating the top 3, removing them to see if they are 15, then checking if each is less than 8.
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 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 with classic P2PKH, but with txout_scriptpubkey the response is
`400 Bad Request sendrawtransaction RPC error -26: scriptpubkey`
Any help is appreciated, I don’t know where I went wrong in the script. I first used 8, but I had to use OP_8, but it still doesn’t work. Edit: I won’t accept that either "(OP_5, OP_EQUAL)"
. You cannot accept anything other than P2PKH.
Discover more from Earlybirds Invest
Subscribe to get the latest posts sent to your email.