0

Related to post Murch Explanation of Segwit Tx Fee Rate he breaks a TX down into:

  • TxHeader
  • TxInput
  • TxOutput

To calculate the weight and the final virtual size of a transaction (P2PKH,P2WPKH,P2SH-P2WPKH)

My question relates to what is the TxHeader in detail. I haven't heard about this classification in any articles.

norisgOG
  • 48
  • 6

1 Answers1

1

When I look at the following Transaction Description Transactions I see the following distinction so I conclude:

TxHeader:

Field Size (in bytes)
Version no 4
Flag 2 (optional only for segwit v0 right now)
In-counter 1 - 9 bytes (varint)
Out-counter 1 - 9 bytes (varint)
lock_time 4 bytes

TxInput:

Field Size (in bytes)
list of inputs (in-counter)-many inputs

TxOutput:

Field Size (in bytes)
list of inputs (out-counter)-many inputs
norisgOG
  • 48
  • 6
  • Can somebody confirm ? – norisgOG Mar 09 '21 at 09:22
  • 1
    The header can vary. You are nearly right. Basically it starts with version and inputCount. If the inputCount = 0 then the inputCount is the flag and the inputCout follows. If the initial inputCount is > 0 then its the inputCount and the inputs are following. – Erhard Dinhobl Mar 09 '21 at 11:07
  • FYFI I coded exactly that data reading: https://github.com/mrqc/bitcoin-blk-file-reader/blob/master/analyze.py – Erhard Dinhobl Mar 09 '21 at 11:07
  • See the readTransaction(...) function there. – Erhard Dinhobl Mar 09 '21 at 11:08
  • 1
    Ok so what your are essentially decribing is, how the algorithm is implemented,got it, but I think looking at your code when the 5 th byte is 0 then the next byte is the flag (not the already read inputCount) and the 7th Byte is the inputCount. Thanks for the Code Snippet very pratical for understanding – norisgOG Mar 09 '21 at 23:47
  • Yes, but be aware: Inbetween those values the inputs' data is there, so you maybe dont want to include this data in a "header". – Erhard Dinhobl Mar 10 '21 at 07:38