Title: Making transaction in python using pybitcointool / pycryptotool Post by: nathnath5 on July 24, 2020, 01:35:12 PM Hello,
I'm currently trying to understand how to make and sign bitcoin transaction in python using pycryptotool library (https://github.com/primal100/pybitcointools (https://github.com/primal100/pybitcointools)). There's an example explaining how to use this library but I don't quite understand the signing part : Quote Code: > tx = c.mktx(inputs,outs) Why is the transaction signed 2 times ? And why is tx serialized and pushed instead of tx2 and tx3 which are signed ? Thank you in advance for your time and your help, your fellow beginner, NathNath Title: Re: Making transaction in python using pybitcointool / pycryptotool Post by: ranochigo on July 25, 2020, 02:04:00 PM In a Bitcoin transaction, each UTXO is signed individually and provides its own signature so that the nodes would know that the UTXO can be spent in that transaction. The transaction has 2 UTXOs so you have to sign both UTXOs, as referenced by index 0 and 1.
Title: Re: Making transaction in python using pybitcointool / pycryptotool Post by: nathnath5 on July 25, 2020, 10:54:14 PM Thank you for your answer :)
So when I create a transaction, i need to sign x times for the x UTXOs in the inputs and increment the index. Am I right? Title: Re: Making transaction in python using pybitcointool / pycryptotool Post by: TheArchaeologist on July 26, 2020, 07:48:33 AM So when I create a transaction, i need to sign x times for the x UTXOs in the inputs and increment the index. Am I right? I am not sure if I'm understanding you question correctly about the inputs and the index. But for the inputs you want to spent you don't have to increment the number. You simply using an unspent output from a previous transaction which has it's own index within the outputs of that transaction. If that didn't make any sense let me try to explain with a (simplified) example:Code: Transaction a1 Title: Re: Making transaction in python using pybitcointool / pycryptotool Post by: pooya87 on July 26, 2020, 08:10:13 AM I am not sure if I'm understanding you question correctly about the inputs and the index. But for the inputs you want to spent you don't have to increment the number. he probably meant the input index in the array of txins meaning "sign input at index 0" then "sign input at index 1",... in the TxIn[] { txin0, txin1,... } Title: Re: Making transaction in python using pybitcointool / pycryptotool Post by: HCP on July 29, 2020, 12:07:41 AM ... And why is tx serialized and pushed instead of tx2 and tx3 which are signed ? Probably the result of a typo... as, logically, given the pattern the dev was using, it should have been "tx3" being serialized. :PI believe that the reason this code actually works is the way Python deals with mutable object references and they way they are passed into/out of functions... In essence, tx2 and tx3 are actually just references to the original "tx" object (although I'm not a Python expert, so feel free to correct me if I'm wrong!)... So, when the code is passing "tx2" and "tx3" to the sign() function... we're actually using the original "tx" object. So when the (accidental?) serialisation of "tx" happens at the end, it all works out. ;) |