I’m attempting to make a SIGHASH_SINGLE transaction.
I’ve two inputs, one output. I perceive that second enter will be not signed (actually?).
Script I’ve is:
#!/usr/bin/env python3
import hashlib
import subprocess
from bitcoin import SelectParams
from bitcoin.core import b2x, lx, COIN, COutPoint, CMutableTxOut, CMutableTxIn, CMutableTransaction, Hash160
from bitcoin.core.script import CScript, OP_DUP, OP_HASH160, OP_EQUALVERIFY, OP_CHECKSIG, SignatureHash, SIGHASH_ALL, SIGHASH_SINGLE
from bitcoin.core.scripteval import VerifyScript, SCRIPT_VERIFY_P2SH
from bitcoin.pockets import CBitcoinAddress, CBitcoinSecret
SelectParams('mainnet')
h = b'personal key bytes in python hex format'
seckey = CBitcoinSecret.from_secret_bytes(h)
txid = lx('tx #1')
vout = 0
txid2 = lx('tx quantity 2')
vout2 = 1
txin = CMutableTxIn(COutPoint(txid, vout))
txin2 = CMutableTxIn(COutPoint(txid2, vout2))
txin_scriptPubKey = CScript([OP_DUP, OP_HASH160, Hash160(seckey.pub), OP_EQUALVERIFY, OP_CHECKSIG])
txout = CMutableTxOut(10000, CBitcoinAddress('output handle').to_scriptPubKey())
tx = CMutableTransaction([txin]+[txin2], [txout])
sighash = SignatureHash(txin_scriptPubKey, tx, 0, SIGHASH_SINGLE)
sig = seckey.signal(sighash) + bytes([SIGHASH_SINGLE])
txin.scriptSig = CScript([sig, seckey.pub])
VerifyScript(txin.scriptSig, txin_scriptPubKey, tx, 0, (SCRIPT_VERIFY_P2SH,))
print(b2x(tx.serialize()))
r=subprocess.run(["/mnt/c/Program Files/Bitcoin/daemon/bitcoin-cli.exe", "sendrawtransaction", b2x(tx.serialize())])
I get error:
error code: -25
error message:
bad-txns-inputs-missingorspent
Each inputs have steadiness, I’m certain of that. Script is run from WSL1 Bash on Home windows.
What am I lacking right here?