Where does the Bitcoin Core code serialize the number of transactions?

0

1

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?

Spencer Dupre

Posted 2017-11-29T04:57:32.787

Reputation: 19

Answers

1

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.

Andrew Chow

Posted 2017-11-29T04:57:32.787

Reputation: 40 910

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 2017-11-29T07:20:22.560