The Vault’s Inventory: Tracking Unspent Transaction Outputs (UTXOs)
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
-
nDepth(Confirmations): Imagine you receive a piece of gold, but the "Assayer's Office" hasn't verified it yet. That gold is "Unconfirmed."nDepthmeasures how many "Pages of History" (blocks) have been written on top of that transaction. Usually, a wallet will not let you spend gold withnDepth = 0unless you were the one who sent it to yourself. It is the "Certainty of the Gold." -
IsSpent: A "Spent" coin is just a memory. You cannot spend the same gold twice. This check ensures that your "Inventory Report" only includes "Live" money. It is the "Prevention of the Double-Spend," the core logic that keeps the internal bank honest. -
IsLockedCoin: As a Sovereign Architect, you have the power to "Lock" specific coins. This is like putting a piece of gold in a "Special Safe" and telling the manager: "Do not touch this gold, no matter what." This is useful for "Long-Term Savings" or for coins that you want to keep "Cold." It is the "Will of the Sovereign," overriding the automated logic of the computer.
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.
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: