The Anatomy of a Coin: Analyzing `src/coins.h`
6. The Anatomy of a Coin: Analyzing src/coins.h
In the database, a Bitcoin is not a physical object; it is a Data Structure. Every "Unspent Output" is stored as a Coin object. This object contains only the essential information needed to verify a future spend. By keeping this structure as "Lean" as possible, Bitcoin Core ensures that the entire world's wealth can be indexed with minimal resources.
For the Sovereign Architect, the Coin structure is the "DNA of the Wealth." It is the proof that your "Balance" is a set of verifiable attributes protected by the laws of the protocol.
Analyzing the DNA: The Coin Structure
In src/coins.h, we see the definition of what a Bitcoin actually "is" inside your computer's memory.
/**
* PEDAGOGICAL ANALYSIS: THE ANATOMY OF WEALTH
* This logic defines the "Properties" of a single coin.
* It is the "Certificate of Ownership" for the network.
*/
class Coin
{
public:
// 1. The Value: How many Satoshis is this coin worth?
CTxOut out;
// 2. The Height: In which block was this coin born?
// 3. IsCoinbase: Was this coin created as a miner's reward?
unsigned int nHeight : 31;
unsigned int fCoinBase : 1;
};
Explaining the DNA: The Attributes of the Mesh
-
"The
CTxOut(The Payload)": This is the core of the coin. It contains thenValue(the amount) and thescriptPubKey(the lock). This is the only information needed to verify that a future transaction has the right to spend it. It is the Value of the Sovereign. -
"The Birth Height": The node stores the block number where the coin was created. This is used for "Timelocks" (Chapter 18 of Volume 7) to ensure that a coin isn't spent before a certain amount of time has passed. It is the Patience of the Machine.
-
"The Coinbase Flag": Miner rewards (Coinbase) have special rules: they cannot be spent until 100 blocks have passed. This flag tells the node: "Be careful with this coin; it is new-born." It is the Maturity of the Protocol.
-
"The Bit-Field Packing": Notice the
: 31and: 1in the code. This is a C++ trick to pack the "Height" and the "Flag" into a single 4-byte space. This saves millions of bytes across the entire UTXO set. It is the Efficiency of the Core.
The Sovereignty of the DNA
The Coin structure is the "Atomic Unit of the Ledger." It ensures that every "Satoshi" has a clear, verifiable history and a rigid set of spending rules. As a Sovereign Architect, you know that "Attributes define Reality." By understanding the internal anatomy of your node's coins, you are ensuring your wealth is moved with the absolute "Mathematical Precision" of the Bitcoin Core. You are the "Master of the DNA."
TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation: