Since BIP144, transaction knowledge consists of two components (regular knowledge and witness knowledge). There are additionally two distinct transaction serialization codecs:
- The legacy serialization format, which shops model quantity, transaction inputs, transaction outputs, and locktime.
- The prolonged serialization format, which additionally has a flag/marker to point the prolonged format is in use, and has witness knowledge for each transaction enter.
The prolonged format should be used if witness knowledge is current. The legacy format should be used if no witness knowledge is current.
The txid is the double-SHA256 hash of the serialized transaction in legacy format, which means that any witness knowledge must be stripped out (because the legacy format doesn’t assist witness knowledge). If the transaction had no witness knowledge within the first place (as pre-segwit transaction do), the txid is simply the hash of the serialized transaction.
The hash (or wtxid) of a transaction is the double-SHA256 hash of the serialization together with potential witness knowledge. If the transaction accommodates no witness knowledge, this similar to the txid.