Estoy tratando de hacer una transacción sighash_single.
Tengo dos entradas, una salida. Entiendo que la segunda entrada no se puede firmar (¿de verdad?).
El guión que tengo es:
#!/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'non-public key bytes in python hex format'
seckey = CBitcoinSecret.from_secret_bytes(h)
txid = lx('tx no 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 tackle').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 Information/Bitcoin/daemon/bitcoin-cli.exe", "sendrawtransaction", b2x(tx.serialize())))
Estoy recibiendo error:
error code: -25
error message:
bad-txns-inputs-missingorspent
Ambas entradas tienen equilibrio, estoy seguro de eso. El script se ejecuta desde WSL1 Bash en Home windows.
¿Qué me estoy perdiendo aquí?
Estoy tratando de hacer una transacción sighash_single.
Tengo dos entradas, una salida. Entiendo que la segunda entrada no se puede firmar (¿de verdad?).
El guión que tengo es:
#!/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'non-public key bytes in python hex format'
seckey = CBitcoinSecret.from_secret_bytes(h)
txid = lx('tx no 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 tackle').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 Information/Bitcoin/daemon/bitcoin-cli.exe", "sendrawtransaction", b2x(tx.serialize())))
Estoy recibiendo error:
error code: -25
error message:
bad-txns-inputs-missingorspent
Ambas entradas tienen equilibrio, estoy seguro de eso. El script se ejecuta desde WSL1 Bash en Home windows.
¿Qué me estoy perdiendo aquí?