The witness data + locktime at the end (hex):
0000000000000000
There are 8 inputs in the transaction.
Are you sure that at least one of the 8 inputs comes from a Segwit address?
At least one input must contain witness data!
I'm guessing this transaction needs to be signed in Legancy format.
They're all UTXOs from a legacy address so I figured that the witness array still needs to be the total length of the inputs.
I have not tested with a bech32 address yet, because I was busy verifying that legacy transaction creation works (it does).
They're all UTXOs from a legacy address so I figured that the witness array still needs to be the total length of the inputs.
I am relatively certain that in this case you are not allowed to create a Segwit transaction. It must be a legancy TX!
Witness Field also not permitted in this TX!
Witness field may only be inserted if at least one input comes from a Segwit address.
BIP141 says this:
The witness is a serialization of all witness fields of the transaction. Each txin is associated with a witness field. A witness field starts with a var_int to indicate the number of stack items for the txin. It is followed by stack items, with each item starts with a var_int to indicate the length. Witness data is NOT script.
A non-witness program (defined hereinafter) txin MUST be associated with an empty witness field, represented by a 0x00. If all txins are not witness program, a transaction's wtxid is equal to its txid.
So if there is no segwit input, it basically means there is no marker, flag, witness field, etc. but what if only some of the inputs are segwit?
I am not sure what the witness is supposed to be in this case.
In this case, hypothetically if there were 8 witness items, they would not be specified as 00 x8 times, but 08 as the stack length and then each stack (containing the relevant scriptsig)?
And if only half of them were witnesses, then it's 04 as stack length and then the 4 stack items?
How does Core even keep track of which input a witness belongs to if there are legacy inputs scattered in the middle?
In that case, please show me a witness transaction only Legancy inputs in the blockchain.
You were right about only legacy inputs transaction since that's what the last sentence of the quote also says. It's at the beginning of the document btw. My question now is how to construct the witness in the following case:
but what if only some of the inputs are segwit?
= segwit
[moderator's note: consecutive posts merged]