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.
251walletModel(parent),252priv(new TransactionTablePriv(this)),253platformStyle(_platformStyle)254{255subscribeToCoreSignals();257columns << QString() << tr("Date") << tr("Type") << tr("Label") << BitcoinUnits::getAmountColumnTitle(walletModel->getOptionsModel()->getDisplayUnit());258priv->refreshWallet(walletModel->wallet());260connect(walletModel->getOptionsModel(), &OptionsModel::displayUnitChanged, this, &TransactionTableModel::updateDisplayUnit);261}263TransactionTableModel::~TransactionTableModel()264{265unsubscribeFromCoreSignals();266delete priv;267}269/** Updates the column title to "Amount (DisplayUnit)" and emits headerDataChanged() signal for table headers to react. */270void TransactionTableModel::updateAmountColumnTitle()271{272columns[Amount] = BitcoinUnits::getAmountColumnTitle(walletModel->getOptionsModel()->getDisplayUnit());273Q_EMIT headerDataChanged(Qt::Horizontal,Amount,Amount);274}276void TransactionTableModel::updateTransaction(const QString &hash, int status, bool showTransaction)277{278Txid updated = Txid::FromHex(hash.toStdString()).value();280priv->updateWallet(walletModel->wallet(), updated, status, showTransaction);281}283void TransactionTableModel::updateConfirmations()284{285// Blocks came in since last poll.286// Invalidate status (number of confirmations) and (possibly) description287// for all rows. Qt is smart enough to only actually request the data for the288// visible rows.289Q_EMIT dataChanged(index(0, Status), index(priv->size()-1, Status));290Q_EMIT dataChanged(index(0, ToAddress), index(priv->size()-1, ToAddress));291}293int TransactionTableModel::rowCount(const QModelIndex &parent) const294{295if (parent.isValid()) {296return 0;297}298return priv->size();299}301int TransactionTableModel::columnCount(const QModelIndex &parent) const302{303if (parent.isValid()) {304return 0;305}306return columns.length();307}309QString TransactionTableModel::formatTxStatus(const TransactionRecord *wtx) const310{311QString status;313switch(wtx->status.status)314{315case TransactionStatus::Unconfirmed:316status = tr("Unconfirmed");317break;318case TransactionStatus::Abandoned:319status = tr("Abandoned");320break;321case TransactionStatus::Confirming:322status = tr("Confirming (%1 of %2 recommended confirmations)").arg(wtx->status.depth).arg(TransactionRecord::RecommendedNumConfirmations);323break;324case TransactionStatus::Confirmed:325status = tr("Confirmed (%1 confirmations)").arg(wtx->status.depth);326break;327case TransactionStatus::Conflicted:328status = tr("Conflicted");329break;330case TransactionStatus::Immature:331status = tr("Immature (%1 confirmations, will be available after %2)").arg(wtx->status.depth).arg(wtx->status.depth + wtx->status.matures_in);332break;333case TransactionStatus::NotAccepted:334status = tr("Generated but not accepted");335break;336}338return status;339}341QString TransactionTableModel::formatTxDate(const TransactionRecord *wtx) const342{343if(wtx->time)344{345return GUIUtil::dateTimeStr(wtx->time);346}347return QString();348}350/* Look up address in address book, if found return label (address)351otherwise just return (address)352*/353QString TransactionTableModel::lookupAddress(const std::string &address, bool tooltip) const354{355QString label = walletModel->getAddressTableModel()->labelForAddress(QString::fromStdString(address));356QString description;357if(!label.isEmpty())358{359description += label;360}361if(label.isEmpty() || tooltip)362{363description += QString(" (") + QString::fromStdString(address) + QString(")");364}365return description;366}368QString TransactionTableModel::formatTxType(const TransactionRecord *wtx) const369{370switch(wtx->type)371{372case TransactionRecord::RecvWithAddress:373return tr("Received with");374case TransactionRecord::RecvFromOther:375return tr("Received from");376case TransactionRecord::SendToAddress:377case TransactionRecord::SendToOther:378return tr("Sent to");379case TransactionRecord::Generated:380return tr("Mined");381default:382return QString();383}384}386QVariant TransactionTableModel::txAddressDecoration(const TransactionRecord *wtx) const387{388switch(wtx->type)389{390case TransactionRecord::Generated:391return QIcon(":/icons/tx_mined");392case TransactionRecord::RecvWithAddress:393case TransactionRecord::RecvFromOther:394return QIcon(":/icons/tx_input");395case TransactionRecord::SendToAddress:396case TransactionRecord::SendToOther:397return QIcon(":/icons/tx_output");398default:399return QIcon(":/icons/tx_inout");400}401}403QString TransactionTableModel::formatTxToAddress(const TransactionRecord *wtx, bool tooltip) const404{405switch(wtx->type)406{407case TransactionRecord::RecvFromOther:408return QString::fromStdString(wtx->address);409case TransactionRecord::RecvWithAddress:410case TransactionRecord::SendToAddress:411case TransactionRecord::Generated:412return lookupAddress(wtx->address, tooltip);413case TransactionRecord::SendToOther:414return QString::fromStdString(wtx->address);415default:416return tr("(n/a)");417}418}420QVariant TransactionTableModel::addressColor(const TransactionRecord *wtx) const421{422// Show addresses without label in a less visible color423switch(wtx->type)424{425case TransactionRecord::RecvWithAddress:426case TransactionRecord::SendToAddress:427case TransactionRecord::Generated:428{429QString label = walletModel->getAddressTableModel()->labelForAddress(QString::fromStdString(wtx->address));430if(label.isEmpty())431return COLOR_BAREADDRESS;432} break;433default:434break;435}436return QVariant();437}439QString TransactionTableModel::formatTxAmount(const TransactionRecord *wtx, bool showUnconfirmed, BitcoinUnits::SeparatorStyle separators) const440{441QString str = BitcoinUnits::format(walletModel->getOptionsModel()->getDisplayUnit(), wtx->credit + wtx->debit, false, separators);442if(showUnconfirmed)443{444if(!wtx->status.countsForBalance)445{446str = QString("[") + str + QString("]");447}448}449return QString(str);450}452QVariant TransactionTableModel::txStatusDecoration(const TransactionRecord *wtx) const453{454switch(wtx->status.status)455{456case TransactionStatus::Unconfirmed:457return QIcon(":/icons/transaction_0");458case TransactionStatus::Abandoned:459return QIcon(":/icons/transaction_abandoned");460case TransactionStatus::Confirming:461switch(wtx->status.depth)462{463case 1: return QIcon(":/icons/transaction_1");464case 2: return QIcon(":/icons/transaction_2");465case 3: return QIcon(":/icons/transaction_3");466case 4: return QIcon(":/icons/transaction_4");467default: return QIcon(":/icons/transaction_5");468};469case TransactionStatus::Confirmed:470return QIcon(":/icons/transaction_confirmed");471case TransactionStatus::Conflicted:472return QIcon(":/icons/transaction_conflicted");473case TransactionStatus::Immature: {474int total = wtx->status.depth + wtx->status.matures_in;475int part = (wtx->status.depth * 4 / total) + 1;476return QIcon(QString(":/icons/transaction_%1").arg(part));477}478case TransactionStatus::NotAccepted:479return QIcon(":/icons/transaction_0");480} // no default case, so the compiler can warn about missing cases481assert(false);482}484QString TransactionTableModel::formatTooltip(const TransactionRecord *rec) const485{486QString tooltip = formatTxStatus(rec) + QString("\n") + formatTxType(rec);487if(rec->type==TransactionRecord::RecvFromOther || rec->type==TransactionRecord::SendToOther ||488rec->type==TransactionRecord::SendToAddress || rec->type==TransactionRecord::RecvWithAddress)489{490tooltip += QString(" ") + formatTxToAddress(rec, true);491}492return tooltip;493}495QVariant TransactionTableModel::data(const QModelIndex &index, int role) const496{497if(!index.isValid())498return QVariant();499TransactionRecord *rec = static_cast<TransactionRecord*>(index.internalPointer());
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.