Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2011-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#include <qt/transactionrecord.h>7#include <chain.h>8#include <interfaces/wallet.h>9#include <key_io.h>11#include <cstdint>13#include <QDateTime>15/* Return positive answer if transaction should be shown in list.16*/17bool TransactionRecord::showTransaction()18{19// There are currently no cases where we hide transactions, but20// we may want to use this in the future for things like RBF.21return true;22}24/*25* Decompose CWallet transaction to model transaction records.26*/27QList<TransactionRecord> TransactionRecord::decomposeTransaction(const interfaces::WalletTx& wtx)28{29QList<TransactionRecord> parts;30int64_t nTime = wtx.time;31CAmount nCredit = wtx.credit;32CAmount nDebit = wtx.debit;33CAmount nNet = nCredit - nDebit;34Txid hash = wtx.tx->GetHash();36bool all_from_me = true;37bool any_from_me = false;38if (wtx.is_coinbase) {39all_from_me = false;40} else {41for (const bool mine : wtx.txin_is_mine)42{43all_from_me = all_from_me && mine;44if (mine) any_from_me = true;45}46}48if (all_from_me || !any_from_me) {49CAmount nTxFee = nDebit - wtx.tx->GetValueOut();51for(unsigned int i = 0; i < wtx.tx->vout.size(); i++)52{53const CTxOut& txout = wtx.tx->vout[i];55if (all_from_me) {56// Change is only really possible if we're the sender57// Otherwise, someone just sent bitcoins to a change address, which should be shown58if (wtx.txout_is_change[i]) {59continue;60}62//63// Debit64//66TransactionRecord sub(hash, nTime);67sub.idx = i;69if (!std::get_if<CNoDestination>(&wtx.txout_address[i]))70{71// Sent to Bitcoin Address72sub.type = TransactionRecord::SendToAddress;73sub.address = EncodeDestination(wtx.txout_address[i]);74}75else76{77// Sent to IP, or other non-address transaction like OP_EVAL78sub.type = TransactionRecord::SendToOther;79sub.address = wtx.comment_to.value_or("");80}82CAmount nValue = txout.nValue;83/* Add fee to first output */84if (nTxFee > 0)85{86nValue += nTxFee;87nTxFee = 0;88}89sub.debit = -nValue;91parts.append(sub);92}94bool mine = wtx.txout_is_mine[i];95if(mine)96{97//98// Credit99//101TransactionRecord sub(hash, nTime);102sub.idx = i; // vout index103sub.credit = txout.nValue;104if (wtx.txout_address_is_mine[i])105{106// Received by Bitcoin Address107sub.type = TransactionRecord::RecvWithAddress;108sub.address = EncodeDestination(wtx.txout_address[i]);109}110else111{112// Received by IP connection (deprecated features), or a multisignature or other non-simple transaction113sub.type = TransactionRecord::RecvFromOther;114sub.address = wtx.from.value_or("");115}116if (wtx.is_coinbase)117{118// Generated119sub.type = TransactionRecord::Generated;120}122parts.append(sub);123}124}125} else {126//127// Mixed debit transaction, can't break down payees128//129parts.append(TransactionRecord(hash, nTime, TransactionRecord::Other, "", nNet, 0));130}132return parts;133}135void TransactionRecord::updateStatus(const interfaces::WalletTxStatus& wtx, const uint256& block_hash, int numBlocks, int64_t block_time)136{137// Determine transaction status139// Sort order, unrecorded transactions sort to the top140int typesort;141switch (type) {142case SendToAddress: case SendToOther:143typesort = 2; break;144case RecvWithAddress: case RecvFromOther:145typesort = 3; break;146default:147typesort = 9;148}149status.sortKey = strprintf("%010d-%01d-%010u-%03d-%d",150wtx.block_height,151wtx.is_coinbase ? 1 : 0,152wtx.time_received,153idx,154typesort);155status.countsForBalance = wtx.is_trusted && !(wtx.blocks_to_maturity > 0);156status.depth = wtx.depth_in_main_chain;157status.m_cur_block_hash = block_hash;159// For generated transactions, determine maturity160if (type == TransactionRecord::Generated) {161if (wtx.blocks_to_maturity > 0)162{163status.status = TransactionStatus::Immature;165if (wtx.is_in_main_chain)166{167status.matures_in = wtx.blocks_to_maturity;168}169else170{171status.status = TransactionStatus::NotAccepted;172}173}174else175{176status.status = TransactionStatus::Confirmed;177}178}179else180{181if (status.depth < 0)182{183status.status = TransactionStatus::Conflicted;184}185else if (status.depth == 0)186{187status.status = TransactionStatus::Unconfirmed;188if (wtx.is_abandoned)189status.status = TransactionStatus::Abandoned;190}191else if (status.depth < RecommendedNumConfirmations)192{193status.status = TransactionStatus::Confirming;194}195else196{197status.status = TransactionStatus::Confirmed;198}199}200status.needsUpdate = false;201}203bool TransactionRecord::statusUpdateNeeded(const uint256& block_hash) const204{205assert(!block_hash.IsNull());206return status.m_cur_block_hash != block_hash || status.needsUpdate;207}209QString TransactionRecord::getTxHash() const210{211return QString::fromStdString(hash.ToString());212}214int TransactionRecord::getOutputIndex() const215{216return idx;217}
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.