TeachMeBitcoin

The Vault’s Inventory: Tracking Unspent Transaction Outputs (UTXOs)

From TeachMeBitcoin, the free encyclopedia Reading time: 4 min

The Vault’s Inventory: Tracking Unspent Transaction Outputs (UTXOs)

To the outside world, your wallet has a "Balance." But to the computer, your wallet has an "Inventory." This inventory is a collection of Unspent Transaction Outputs (UTXOs). Every single satoshi you own is tied to a specific "Output" from a previous transaction. You can think of a UTXO as a "Digital Bill" or a "Piece of Gold" of a specific weight. If your balance is 1.5 BTC, you might actually have three pieces of gold: one weighing 0.5 BTC, one weighing 0.8 BTC, and one weighing 0.2 BTC. The wallet's primary job is to keep a meticulous "Inventory Report" of these pieces. This is handled by the AvailableCoins function in src/wallet/spend.cpp.

For the Sovereign Architect, the UTXO inventory is the "Raw Material" of your financial power. When you make a payment, the wallet "Picks" which pieces of gold to melt down and reshape into new coins. This "Selection" has massive implications for your fees and your privacy. If you pick too many small pieces, your transaction will be "Heavy" and expensive. If you pick pieces that belong to different labels, you will link those identities together. Understanding the "Inventory" is the first step in mastering the "Art of the Selection."

Analyzing the Inventory Audit: AvailableCoins

In the source code, AvailableCoins scans your entire history and identifies every coin that is "Safe" to spend. A coin is only considered "Safe" if it is confirmed, not already spent, and not "Locked" by the user.

/**
 * This function builds the list of all spendable coins in the wallet.
 */
CoinsResult AvailableCoins(const CWallet& wallet, ...)
{
 CoinsResult result;

 // 1. We loop through every "Transaction Output" (TXO) that the wallet knows about.
 for (const auto& [outpoint, txo] : wallet.GetTXOs()) {
 const CWalletTx& wtx = txo.GetWalletTx();

 // 2. We perform a "Depth Audit." Is the transaction confirmed enough?
 int nDepth = wallet.GetTxDepthInMainChain(wtx);
 if (nDepth < 0) continue; // It's conflicted or invalid.
 if (nDepth == 0 && !wtx.InMempool()) continue; // It hasn't been seen by the network.

 // 3. We check if the coin is already "Spent" by an unconfirmed transaction.
 if (wallet.IsSpent(outpoint)) continue;

 // 4. We check if the user has "Manually Locked" the coin (Coin Control).
 if (wallet.IsLockedCoin(outpoint)) continue;

 // 5. If it passes all tests, we add it to the inventory report.
 result.Add(COutput(outpoint, txo.GetTxOut(), nDepth, ...));
 }

 return result;
}

Explaining the Inventory: The Gold Piece Inspection

The Mastery of the Vault

By understanding AvailableCoins, you are learning to see the "Raw Data" that the GUI hides from you. In the "Coin Control" menu of Bitcoin Core, you can see this inventory report in all its glory. You can see the Outpoint (the ID of the piece of gold), the Amount, and the Confirmations. This visibility is what allows you to "Micromanage" your bank. You are no longer just "Sending Money"; you are "Strategically Deploying Assets." You are the "Master of the Inventory," the one who ensures every satoshi is used with purpose.


☕ 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!