I am using golang's btcd as a basis for creating some server-side tools for handling transactions. I found a good example for creating a basic one-input-one-output transaction to get me started on the implementation, and I have also read the documentation heavily on the technical specifics here. I have also looked at the other btcsuite libraries pretty heavily to try to gain more insight. To be clear, I am NOT expecting any of these tools to issue the transaction or anything like that; I understand that this was written out of btcd in particular for very, very good reasons. I am just trying to use these tools to create valid transactions that I can issue later.
I am still incredibly confused on the particulars in implementing multiple input, multiple output transactions and the scripts that we use on them. A few topics:
- I'm familiar with the script tools in btcd, the link goes to the most common one used, but all of these scripts are used for one specific output. There seems to be absolutely no documentation anywhere about how to provide scripting for multiple outputs. If I'm doing a normal P2PK or P2PKH transaction, do I simply concatenate the scripts for all the various outputs, or what?
In the create Transaction example in the HelloBitcoin example I've linked above, the overall magic happens near the end with:
buffer.Write(version) buffer.Write(inputs) buffer.Write(inputTransactionBytesReversed) buffer.Write(outputIndexBytes) buffer.WriteByte(byte(scriptSigLength)) buffer.Write(scriptSig) buffer.Write(sequence) buffer.Write(numOutputs) buffer.Write(satoshiBytes) buffer.WriteByte(byte(scriptPubKeyLength)) buffer.Write(scriptPubKey) buffer.Write(lockTimeField)
And I feel like there are a lot of unanswered questions on how to expand this to handle multiple inputs and multiple outputs. For the inputs, is it as simple as taking all the input transactions into little-endian, noting the correct number in inputs
, and going from there? For outputs, do you just have an individual block of to satoshiBytes
to scriptPubKey
? I can't find in the documentation how this is supposed to all glue together, and at this point I feel like I need some help with the nuts and bolts of this. Thanks in advance for any help - if we can get these two points answered I might end up making more questions from the stuff that will inevitably result from this.