I understand how txs were structured pre segwit, now I am trying to understand how they work post segwit.
e.g I am using is
One of the articles I am using to try to understand was:
This article says the new structure of a TX is:
Serialization format for transaction with SegWit:
Field Size Name Type Description
4 version int32_t Transaction data format version
1 marker char Must be zero
1 flag char Must be nonzero
1+ txin_count var_int Number of transaction inputs
41+ txins txin A list of one or more transaction inputs
1+ txout_count var_int Number of transaction outputs
9+ txouts txouts A list of one or more transaction outputs
1+ script_witnesses script_witnesses The witness structure as a serialized byte array
4 lock_time uint32_t The block number or timestamp until which the transaction is locked
Now the script witness consists of:
Double SHA256 of the serialization of:
1. nVersion of the transaction (4-byte little endian)
2. hashPrevouts (32-byte hash)
3. hashSequence (32-byte hash)
4. outpoint (32-byte hash + 4-byte little endian)
5. scriptCode of the input (serialized as scripts inside CTxOuts)
6. value of the output spent by this input (8-byte little endian)
7. nSequence of the input (4-byte little endian)
8. hashOutputs (32-byte hash)
9. nLocktime of the transaction (4-byte little endian)
10. sighash type of the signature (4-byte little endian)
Now when I look at:
DUP HASH160 PUSHDATA(20)[caad1c0359b179cb13a4abd386d65846f0ed49db] EQUALVERIFY CHECKSIG
The input script sig (ScriptSig: PUSHDATA(22)[0014c6d9370d4ba53b3f07ff918fffd277a44fc1bca5] ) used to be part of the input in pre segwit. But there is no “script sig” in segwit, so if this part of the “script witness”?
And “DUP HASH160 PUSHDATA(20)[caad1c0359b179cb13a4abd386d65846f0ed49db] EQUALVERIFY CHECKSIG
used to be the output script that is pushed onto the stack. Is this a part of the “Script witness” too?
Also, if I have two inputs, will I have two script witnesses? (because pre segwit each input had its own script, and each output had a pubKey script)
Also, this is a segwit tx. Is there any change in which a block is structured under segwit? If yes, any good doc I ca go over to understand that?
I know these are a lot of questions. Sorry.