Author

Topic: At which point transactions are put together? [unsolved] (Read 73 times)

full member
Activity: 297
Merit: 133
I have python script for making SIGHASH_SINGLE transaction.
It is using:

from bitcoin.core import *
from bitcoin.core.script import *
from bitcoin.wallet import *
from bitcoin.core.scripteval import VerifyScript, SCRIPT_VERIFY_P2SH

For now it is on testnet, I have balance.

My question is at which stage of getting ready the transaction the both inputs are going into one variable?

Code:
target_scriptPubKey = destination_address.to_scriptPubKey()

txins= []
txin1 = CTxIn(COutPoint(lx(txid1), vout1))
txin2 = CTxIn(COutPoint(lx(txid2), vout2))
txins=[txin1,txin2]

txout = CTxOut(amount_less_fee, target_scriptPubKey)

tx = CMutableTransaction(txins, [txout])

txin_index = 0

redeem_script1 = address1.to_redeemScript()
redeem_script2 = address2.to_redeemScript()

sighash1 = SignatureHash(redeem_script1, tx, txin_index, SIGHASH_SINGLE, amount=amount1, sigversion=SIGVERSION_WITNESS_V0)
sighash2 = SignatureHash(redeem_script2, tx, txin_index, SIGHASH_SINGLE, amount=amount2, sigversion=SIGVERSION_WITNESS_V0)

signature1 = seckey1.sign(sighash1) + bytes([SIGHASH_SINGLE])
signature2 = seckey2.sign(sighash2) + bytes([SIGHASH_SINGLE])
witness1 = [signature1, public_key1]
witness2 = [signature2, public_key2]
witness1next = CScript(witness1)
witness2next = CScript(witness2)
ctxinwitnesses1 = [CTxInWitness(CScriptWitness(witness1))]
ctxinwitnesses2 = [CTxInWitness(CScriptWitness(witness2))]

tx.wit = CTxWitness(ctxinwitnesses1)

VerifyScript(witness1next, scriptPubKey1, tx, 0, (SCRIPT_VERIFY_P2SH,))

print(b2x(tx.serialize()))
Jump to: