TeachMeBitcoin

The Accountant's View: Exploring `gettxoutsetinfo`

From TeachMeBitcoin, the free encyclopedia Reading time: 2 min

The Accountant's View: Exploring gettxoutsetinfo

If you want to know the "Total Amount of Bitcoin in Existence," you don't look at the blocks; you look at the UTXO Set (Unspent Transaction Output Set). This is the "Current Balance" of every address in the world. The command gettxoutsetinfo is the "Global Balance Sheet." It is the "Audit of Every Penny."

Analyzing the "Total Sum" Code

In the source code (src/rpc/blockchain.cpp), this command performs a "Massive Calculation." It must sum up every single unspent output in the entire database.

/**
 * This function performs the "Global Audit."
 */
static RPCMethod gettxoutsetinfo()
{
 // ... (Arguments omitted)
 [](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
{
 ChainstateManager& chainman = EnsureAnyChainman(request.context);
 Chainstate& active_chainstate = chainman.ActiveChainstate();

 // We must "Flush" the data to the disk to get an accurate count.
 active_chainstate.ForceFlushStateToDisk();

 // We call the 'Kernel' to do the heavy lifting.
 CCoinsStats stats;
 if (GetUTXOStats(active_chainstate.CoinsDB(), chainman.m_blockman, stats)) {
 UniValue obj(UniValue::VOBJ);
 obj.pushKV("height", stats.nHeight);
 obj.pushKV("txouts", stats.nTransactionOutputs);
 obj.pushKV("total_amount", ValueFromAmount(stats.nTotalAmount));
 return obj;
 }
}

Explaining the Audit to a Non-Coder

The Weight of the Ledger

gettxoutsetinfo also reports the disk_size of the database. This is the "Physical Weight" of the world's money. As more people use Bitcoin, the UTXO set grows. This command allows the "Sovereign Librarian" to monitor the "Resource Cost" of decentralization. It is the "Balance Sheet of the Future."


☕ Help support TeachMeBitcoin

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:

Ethereum: 0x578417C51783663D8A6A811B3544E1f779D39A85
Bitcoin: bc1q77k9e95rn669kpzyjr8ke9w95zhk7pa5s63qzz
Solana: 4ycT2ayqeMucixj3wS8Ay8Tq9NRDYRPKYbj3UGESyQ4J
Address copied to clipboard!