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
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.
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.