How do I sign a
P2SH transaction in Python? I am using the Python API that ships with the bitcoin source code, in directory
bitcoin/test/functional. I'm using
Here is a fragment of my unit test, it works as I expect. It creates a transaction, signs it, and broadcasts it:
# w0_rpc is a wallet created with get_wallet_rpc(): addr1 = w0_rpc.getnewaddress() tx2 = CTransaction() # txid0 is the ID of a previous TX, v is the index of the relevant output: tx2.vin.append(CTxIn(COutPoint(int(txid0, 16), v), b"")) # For now, send to a dummy address: tx2.vout.append(CTxOut(int(9 * COIN), CScript([OP_TRUE]))) tx2 = w0_rpc.signrawtransactionwithwallet(ToHex(tx2))["hex"] #tx2.vin.scriptSig = CScript(signature, public_key) txid = n1.sendrawtransaction(tx2, True)
Instead of making the call to
signrawtransactionwithwallet(), I would like to explicity assign a value to
tx2.vin.scriptSig. I gather that this value should look something like
(signature, public_key), but I can't figure out how to do it.
How do I go about this? Is there any documentation of this Python library? So far I am looking at the existing Python test cases, and following the docs for the Bitcoin RPC interface.