user137537: I'm trying to parse a bitcoin block.
I took as an example this block from 2019. I'm trying to parse the first transaction.
I don't understand how to calculate how many bytes I have to read for the "Witnesses"?
By "Witnesses", I refer to this table
Here is my result :
magic_no (4 bytes) : d9b4bef9
block_size (4 bytes) : 1236518
version (4 bytes) : 568442880
prev_hash (32 bytes) : 0000000000000000001437c1e52bc699fb299cac6d2a61a88210b995e45d603e
hash_markle_root (32 bytes) : ed3aba45d11a87c888ffb76a6af7cc1fbddd4a299f285379640c29188110fcf3
time (4 bytes) : 1575857336
bits (4 bytes) : 387308498
nonce (4 bytes) : 2292915727
Tx count (3 bytes) : 2735
Version (4 bytes) : [0 0 0 1]
Flag (2 bytes) : [1 0]
Tx In Count (1 bytes) : 1

*----- START TX Inputs -----*

*----- TxIn 1 -----*

Previous Tx Hash (32 bytes) : 0000000000000000000000000000000000000000000000000000000000000000
Previous Txout Index (4 bytes) : 4294967295
Tx In Script Len (1 bytes) : 85
Tx In Script (85 bytes) : 0348440941d77b6b2f7e726e41d77b6b2e3f8d4a2f4254432e544f502ffabe6d6d19437c0ebcb8916cb51c14eccc000373c8c56bac89feca39a132755acf337f158000000000000000e300518d901a000000000000
Sequence no (4 bytes) : ffffffff
*----- END TX Inputs -----*

Tx Out counter (1 bytes) : 3

*----- START TX Outputs -----*

*----- TxOut 1 -----*
Amount (8 bytes) : 1262724620
Tx Out Script Len (1 bytes) : 25
Tx In Script (25 bytes) : 76a914ba507bae8f1643d2556000ca26b9301b9069dc6b88ac

*----- TxOut 2 -----*
Amount (8 bytes) : 0
Tx Out Script Len (1 bytes) : 38
Tx In Script (38 bytes) : 6a24aa21a9ed36e74c1ca41a78209321759be06054f3ae9b3cd9feaa0f3979f5d9b5d02f286c

*----- TxOut 3 -----*
Amount (8 bytes) : 0
Tx Out Script Len (1 bytes) : 38
Tx In Script (38 bytes) : 6a24b9e11b6d04079a724511b5eac6db73004c5326521f1cc7f0104294285aec8a0dd3c59881

*----- END TX Outputs -----*

Here are the 128 next bytes :
[1 32 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 1 82 246 143 178 43 131 54 243 136 69 149 88 83 79 230 217 254 150 64 45 100 31 124 170 90 141 101 98 30 236 144 89 1 0 0 0 106 71 48 68 2 32 3 14 228 13 162 14 179 94 25 153 151 242 101 101 181 13 61 83 105 57 168 195 125 68 13 39 247 201 82 62 126 228 2 32 118 168 227 118 230 74 50 52 141]


user5406: If there is a witness section in a transaction, the transaction must have one witness stack for each input. You therefore will expect the same number of witness stacks as the input counter. Each witness stack begins by telling you the number of elements in the stack. Each element in the stack starts by telling you its length.

user208: The serialization format for witnesses is described in BIP144.
The rough structure is:

For each transaction input (implicitly, there is no separate indicator of how many inputs there are), there is a witness stack structure, consisting of:

A compactsize encoded number of stack elements
For each stack element:

A compactsize encoded length of the stack element
That many bytes for the contents of the stack element.





Applied to your bytes:

The is one input, so one witness stack

The first witness stack consists of:

1: the number of stack elements (1)
For each stack element

The first stack element

32: the length of the first stack element
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0: the contents of the first witness element (32 times the 0 byte)








0 0 0 0: the transaction's locktime

After that, the next transaction starts.

137537: <p>I'm trying to parse a bitcoin block.
I took as an example <a href="https://explorer.btc.com/btc/block/607304" rel="nofollow noreferrer">this block from 2019</a>. I'm trying to parse the <a href="https://explorer.btc.com/btc/transaction/fc10f85d934b0b0d37e3635545e72d546c57bc40be9a6dac717cd4bba77ee003" rel="nofollow noreferrer">first transaction</a>.</p>
<p>I don't understand how to calculate how many bytes I have to read for the &quot;Witnesses&quot;?<br />
By &quot;Witnesses&quot;, I refer to <a href="https://en.bitcoin.it/wiki/Transaction#General_format_of_a_Bitcoin_transaction_.28inside_a_block.29" rel="nofollow noreferrer">this table</a></p>
<p>Here is my result :</p>
<pre><code>magic_no (4 bytes) : d9b4bef9
block_size (4 bytes) : 1236518
version (4 bytes) : 568442880
prev_hash (32 bytes) : 0000000000000000001437c1e52bc699fb299cac6d2a61a88210b995e45d603e
hash_markle_root (32 bytes) : ed3aba45d11a87c888ffb76a6af7cc1fbddd4a299f285379640c29188110fcf3
time (4 bytes) : 1575857336
bits (4 bytes) : 387308498
nonce (4 bytes) : 2292915727
Tx count (3 bytes) : 2735
Version (4 bytes) : [0 0 0 1]
Flag (2 bytes) : [1 0]
Tx In Count (1 bytes) : 1

*----- START TX Inputs -----*

*----- TxIn 1 -----*

Previous Tx Hash (32 bytes) : 0000000000000000000000000000000000000000000000000000000000000000
Previous Txout Index (4 bytes) : 4294967295
Tx In Script Len (1 bytes) : 85
Tx In Script (85 bytes) : 0348440941d77b6b2f7e726e41d77b6b2e3f8d4a2f4254432e544f502ffabe6d6d19437c0ebcb8916cb51c14eccc000373c8c56bac89feca39a132755acf337f158000000000000000e300518d901a000000000000
Sequence no (4 bytes) : ffffffff
*----- END TX Inputs -----*

Tx Out counter (1 bytes) : 3

*----- START TX Outputs -----*

*----- TxOut 1 -----*
Amount (8 bytes) : 1262724620
Tx Out Script Len (1 bytes) : 25
Tx In Script (25 bytes) : 76a914ba507bae8f1643d2556000ca26b9301b9069dc6b88ac

*----- TxOut 2 -----*
Amount (8 bytes) : 0
Tx Out Script Len (1 bytes) : 38
Tx In Script (38 bytes) : 6a24aa21a9ed36e74c1ca41a78209321759be06054f3ae9b3cd9feaa0f3979f5d9b5d02f286c

*----- TxOut 3 -----*
Amount (8 bytes) : 0
Tx Out Script Len (1 bytes) : 38
Tx In Script (38 bytes) : 6a24b9e11b6d04079a724511b5eac6db73004c5326521f1cc7f0104294285aec8a0dd3c59881

*----- END TX Outputs -----*
</code></pre>
<p>Here are the 128 next bytes :</p>
<pre><code>[1 32 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 1 82 246 143 178 43 131 54 243 136 69 149 88 83 79 230 217 254 150 64 45 100 31 124 170 90 141 101 98 30 236 144 89 1 0 0 0 106 71 48 68 2 32 3 14 228 13 162 14 179 94 25 153 151 242 101 101 181 13 61 83 105 57 168 195 125 68 13 39 247 201 82 62 126 228 2 32 118 168 227 118 230 74 50 52 141]
</code></pre>
 5406: <p>If there is a witness section in a transaction, the transaction must have one witness stack for each input. You therefore will expect the same number of witness stacks as the input counter. Each witness stack begins by telling you the number of elements in the stack. Each element in the stack starts by telling you its length.</p>
 208: <p>The serialization format for witnesses is described in BIP144.</p>
<p>The rough structure is:</p>
<ul>
<li>For each transaction input (implicitly, there is no separate indicator of how many inputs there are), there is a witness stack structure, consisting of:
<ul>
<li>A compactsize encoded number of stack elements</li>
<li>For each stack element:
<ul>
<li>A compactsize encoded length of the stack element</li>
<li>That many bytes for the contents of the stack element.</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>Applied to your bytes:</p>
<ul>
<li>The is one input, so one witness stack
<ul>
<li>The first witness stack consists of:
<ul>
<li><code>1</code>: the number of stack elements (1)</li>
<li>For each stack element
<ul>
<li>The first stack element
<ul>
<li><code>32</code>: the length of the first stack element</li>
<li><code>0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0</code>: the contents of the first witness element (32 times the 0 byte)</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><code>0 0 0 0</code>: the transaction's locktime</li>
</ul>
<p>After that, the next transaction starts.</p>
