<p>The transactions are passed in as a vector. Bitcoin Core's serialization framework understands that all vectors should be serialized with a compact sized unsigned integer preceding the serialization of the data within the vector itself.</p>

CC BY-SA 3.0
2017-11-29T07:20:22.560Z
Just want to add that "a compact sized unsigned integer preceding each object in the vector" might be confusing, as there is only one CompactSize int preceding the entire set.
Spencer Dupre
CC BY-SA 3.0
2017-11-29T06:41:29.960Z
2017-11-29T07:33:09.027Z
2017-11-29T07:33:09.027Z
Ava Chow
<p>Unsigned integer?  This is NOT a good thing, because a PROPRIETARY routine created by the cryptocurrency ISSUER can instantly ALTER the block's AUTHENTICITY, and ergo, it's REAL VALUE.  (i.e. ZERO...like any form of COUNTERFEIT or &quot;Ponzi unit&quot;.  Or are We mistaken?)</p>

CC BY-SA 4.0
2022-02-01T18:10:31.463Z
This does not provide an answer to the question. Once you have sufficient [reputation](https://bitcoin.stackexchange.com/help/whats-reputation) you will be able to [comment on any post](https://bitcoin.stackexchange.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/83720)
Saxtheowl
CC BY-SA 4.0
2022-01-28T09:01:18.653Z
2022-01-28T09:01:18.653Z
C.L.Corrente
<p>I've been studying the Bitcoin Core code, and I noticed that it uses a template READWRITE to serialize data structures for storing blocks.  But it never seems to actually call "READWRITE(nTxs)", the VARINT (CompactSize) that encodes the number of transactions.  It reads the transactions to a vector (primitives/block.h), and it almost seems like it just magically knows how many txs there are.  What gives?</p>

<bitcoin-core><bitcoin-core-development><c++>
Where does the Bitcoin Core code serialize the number of transactions?
Spencer Dupre
# Where does the Bitcoin Core code serialize the number of transactions?

(Asked by: username_0 on 2017-11-29)

I've been studying the Bitcoin Core code, and I noticed that it uses a template READWRITE to serialize data structures for storing blocks. But it never seems to actually call "READWRITE(nTxs)", the VARINT (CompactSize) that encodes the number of transactions. It reads the transactions to a vector (primitives/block.h), and it almost seems like it just magically knows how many txs there are. What gives?

**Tags:** bitcoin-core, bitcoin-core-development, c++


---

## 2 answers

### Answer by username_1 on 2017-11-29. Score: 1 | Accepted answer

The transactions are passed in as a vector. Bitcoin Core's serialization framework understands that all vectors should be serialized with a compact sized unsigned integer preceding the serialization of the data within the vector itself.

> **Comments:**
> **username_0**: Just want to add that "a compact sized unsigned integer preceding each object in the vector" might be confusing, as there is only one CompactSize int preceding the entire set.  

---

### Answer by username_2 on 2022-01-28. Score: 0

Unsigned integer? This is NOT a good thing, because a PROPRIETARY routine created by the cryptocurrency ISSUER can instantly ALTER the block's AUTHENTICITY, and ergo, it's REAL VALUE. (i.e. ZERO...like any form of COUNTERFEIT or "Ponzi unit". Or are We mistaken?)

> **Comments:**
> **username_3**: This does not provide an answer to the question. Once you have sufficient [reputation](https://bitcoin.stackexchange.com/help/whats-reputation) you will be able to [comment on any post](https://bitcoin.stackexchange.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/83720)  

---

