0
I'm trying to consolidate multiple inputs into a single output, all left over is for the miner.
When I send my transaction to a peer, it is never mined. I believe something is invalid in the multi-input signatures.
This is a sample input transaction for 1MeTVq6X8LCtcRDG4MNz1QVezxzxyffSTL:
in_transactions = []
txid =
lx('bad6a00b1ab3c453a3569b4b5373fcaaeefaa01b1e48efcb118c1e1e08597382')
vout = 4
txin = CMutableTxIn(COutPoint(txid, vout))
in_transactions.append(txin)
This is how I create and validate signatures:
seckey = CBitcoinSecret("L1WIFKey...L1WIFKey")
# Create that scriptPubKey from scratch using the pubkey
# This is our signature to open each input
our_scriptPubKey = CScript([OP_DUP, OP_HASH160, Hash160(seckey.pub), OP_EQUALVERIFY, OP_CHECKSIG])
# Create the txout.
their_scriptPubKey = CBitcoinAddress(output_address).to_scriptPubKey()
txout = CMutableTxOut((btc_i_have - minner_fee) * COIN, their_scriptPubKey)
# Create the unsigned transaction.
# in_transactions is a list of [txin,txin,...]
tx = CMutableTransaction(in_transactions, [txout])
# Set the scriptSig of our transaction inputs appropriately.
# THE BUG *MIGHT* BE SOMEWHERE HERE
for idx, txin in enumerate(in_transactions):
sighash = SignatureHash(our_scriptPubKey, tx, idx, SIGHASH_ALL)
sig = seckey.sign(sighash) + bytes([SIGHASH_ALL])
txin.scriptSig = CScript([sig, seckey.pub])
VerifyScript(txin.scriptSig, our_scriptPubKey, tx, idx, (SCRIPT_VERIFY_P2SH,))
# finally this is the raw transaction
raw_transaction = b2x(tx.serialize())
I wonder if I'm signing the inputs wrong when I do it one by one.
Thanks in advance.
EDIT:
The code works, the error is silent. The transaction was dropped silently by the network. It was a wrong transaction because one of my vout was pointing to a wrong output.
Are you sure that all of the inputs correspond to the same address that you are using? What is the exact error that you are getting? – Andrew Chow – 2017-12-23T07:28:02.477
also have a look here: https://bitcoin.stackexchange.com/questions/41209/how-to-sign-a-transaction-with-multiple-inputs
– pebwindkraft – 2017-12-23T09:43:47.747indeed it works. my issue was a wrong vout. – David Rz Ayala – 2017-12-24T08:24:11.347