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?
2 Answers
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.
-
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. Commented Nov 29, 2017 at 7:20
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?)
-
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review Commented Feb 1, 2022 at 18:10