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/walletview.h>7#include <qt/addressbookpage.h>8#include <qt/askpassphrasedialog.h>9#include <qt/clientmodel.h>10#include <qt/guiutil.h>11#include <qt/optionsmodel.h>12#include <qt/overviewpage.h>13#include <qt/platformstyle.h>14#include <qt/receivecoinsdialog.h>15#include <qt/sendcoinsdialog.h>16#include <qt/signverifymessagedialog.h>17#include <qt/transactiontablemodel.h>18#include <qt/transactionview.h>19#include <qt/walletmodel.h>21#include <interfaces/node.h>22#include <node/interface_ui.h>23#include <util/strencodings.h>25#include <QAction>26#include <QFileDialog>27#include <QHBoxLayout>28#include <QProgressDialog>29#include <QPushButton>30#include <QVBoxLayout>32WalletView::WalletView(WalletModel* wallet_model, const PlatformStyle* _platformStyle, QWidget* parent)33: QStackedWidget(parent),34walletModel(wallet_model),35platformStyle(_platformStyle)36{37assert(walletModel);39// Create tabs40overviewPage = new OverviewPage(platformStyle);41overviewPage->setWalletModel(walletModel);43transactionsPage = new QWidget(this);44QVBoxLayout *vbox = new QVBoxLayout();45QHBoxLayout *hbox_buttons = new QHBoxLayout();46transactionView = new TransactionView(platformStyle, this);47transactionView->setModel(walletModel);49vbox->addWidget(transactionView);50QPushButton *exportButton = new QPushButton(tr("&Export"), this);51exportButton->setToolTip(tr("Export the data in the current tab to a file"));52if (platformStyle->getImagesOnButtons()) {53exportButton->setIcon(platformStyle->SingleColorIcon(":/icons/export"));54}55hbox_buttons->addStretch();56hbox_buttons->addWidget(exportButton);57vbox->addLayout(hbox_buttons);58transactionsPage->setLayout(vbox);60receiveCoinsPage = new ReceiveCoinsDialog(platformStyle);61receiveCoinsPage->setModel(walletModel);63sendCoinsPage = new SendCoinsDialog(platformStyle);64sendCoinsPage->setModel(walletModel);66usedSendingAddressesPage = new AddressBookPage(platformStyle, AddressBookPage::ForEditing, AddressBookPage::SendingTab, this);67usedSendingAddressesPage->setModel(walletModel->getAddressTableModel());69usedReceivingAddressesPage = new AddressBookPage(platformStyle, AddressBookPage::ForEditing, AddressBookPage::ReceivingTab, this);70usedReceivingAddressesPage->setModel(walletModel->getAddressTableModel());72addWidget(overviewPage);73addWidget(transactionsPage);74addWidget(receiveCoinsPage);75addWidget(sendCoinsPage);77connect(overviewPage, &OverviewPage::transactionClicked, this, &WalletView::transactionClicked);78// Clicking on a transaction on the overview pre-selects the transaction on the transaction history page79connect(overviewPage, &OverviewPage::transactionClicked, transactionView, qOverload<const QModelIndex&>(&TransactionView::focusTransaction));81connect(overviewPage, &OverviewPage::outOfSyncWarningClicked, this, &WalletView::outOfSyncWarningClicked);83connect(sendCoinsPage, &SendCoinsDialog::coinsSent, this, &WalletView::coinsSent);84// Highlight transaction after send85connect(sendCoinsPage, &SendCoinsDialog::coinsSent, transactionView, qOverload<const Txid&>(&TransactionView::focusTransaction));87// Clicking on "Export" allows to export the transaction list88connect(exportButton, &QPushButton::clicked, transactionView, &TransactionView::exportClicked);90// Pass through messages from sendCoinsPage91connect(sendCoinsPage, &SendCoinsDialog::message, this, &WalletView::message);92// Pass through messages from transactionView93connect(transactionView, &TransactionView::message, this, &WalletView::message);95connect(this, &WalletView::setPrivacy, overviewPage, &OverviewPage::setPrivacy);96connect(this, &WalletView::setPrivacy, this, &WalletView::disableTransactionView);98// Receive and pass through messages from wallet model99connect(walletModel, &WalletModel::message, this, &WalletView::message);101// Handle changes in encryption status102connect(walletModel, &WalletModel::encryptionStatusChanged, this, &WalletView::encryptionStatusChanged);104// Balloon pop-up for new transaction105connect(walletModel->getTransactionTableModel(), &TransactionTableModel::rowsInserted, this, &WalletView::processNewTransaction);107// Ask for passphrase if needed108connect(walletModel, &WalletModel::requireUnlock, this, &WalletView::unlockWallet);110// Show progress dialog111connect(walletModel, &WalletModel::showProgress, this, &WalletView::showProgress);112}114WalletView::~WalletView() = default;116void WalletView::setClientModel(ClientModel *_clientModel)117{118this->clientModel = _clientModel;120overviewPage->setClientModel(_clientModel);121sendCoinsPage->setClientModel(_clientModel);122walletModel->setClientModel(_clientModel);123}125void WalletView::processNewTransaction(const QModelIndex& parent, int start, int /*end*/)126{127// Prevent balloon-spam when initial block download is in progress128if (!clientModel || clientModel->node().isInitialBlockDownload()) {129return;130}132TransactionTableModel *ttm = walletModel->getTransactionTableModel();133if (!ttm || ttm->processingQueuedTransactions())134return;136QString date = ttm->index(start, TransactionTableModel::Date, parent).data().toString();137qint64 amount = ttm->index(start, TransactionTableModel::Amount, parent).data(Qt::EditRole).toLongLong();138QString type = ttm->index(start, TransactionTableModel::Type, parent).data().toString();139QModelIndex index = ttm->index(start, 0, parent);140QString address = ttm->data(index, TransactionTableModel::AddressRole).toString();141QString label = GUIUtil::HtmlEscape(ttm->data(index, TransactionTableModel::LabelRole).toString());143Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label, GUIUtil::HtmlEscape(walletModel->getWalletName()));144}146void WalletView::gotoOverviewPage()147{148setCurrentWidget(overviewPage);149}151void WalletView::gotoHistoryPage()152{153setCurrentWidget(transactionsPage);154}156void WalletView::gotoReceiveCoinsPage()157{158setCurrentWidget(receiveCoinsPage);159}161void WalletView::gotoSendCoinsPage(QString addr)162{163setCurrentWidget(sendCoinsPage);165if (!addr.isEmpty())166sendCoinsPage->setAddress(addr);167}169void WalletView::gotoSignMessageTab(QString addr)170{171// calls show() in showTab_SM()172SignVerifyMessageDialog *signVerifyMessageDialog = new SignVerifyMessageDialog(platformStyle, this);173signVerifyMessageDialog->setAttribute(Qt::WA_DeleteOnClose);174signVerifyMessageDialog->setModel(walletModel);175signVerifyMessageDialog->showTab_SM(true);177if (!addr.isEmpty())178signVerifyMessageDialog->setAddress_SM(addr);179}181void WalletView::gotoVerifyMessageTab(QString addr)182{183// calls show() in showTab_VM()184SignVerifyMessageDialog *signVerifyMessageDialog = new SignVerifyMessageDialog(platformStyle, this);185signVerifyMessageDialog->setAttribute(Qt::WA_DeleteOnClose);186signVerifyMessageDialog->setModel(walletModel);187signVerifyMessageDialog->showTab_VM(true);189if (!addr.isEmpty())190signVerifyMessageDialog->setAddress_VM(addr);191}193bool WalletView::handlePaymentRequest(const SendCoinsRecipient& recipient)194{195return sendCoinsPage->handlePaymentRequest(recipient);196}198void WalletView::showOutOfSyncWarning(bool fShow)199{200overviewPage->showOutOfSyncWarning(fShow);201}203void WalletView::encryptWallet()204{205auto dlg = new AskPassphraseDialog(AskPassphraseDialog::Encrypt, this);206dlg->setModel(walletModel);207connect(dlg, &QDialog::finished, this, &WalletView::encryptionStatusChanged);208GUIUtil::ShowModalDialogAsynchronously(dlg);209}211void WalletView::backupWallet()212{213QString filename = GUIUtil::getSaveFileName(this,214tr("Backup Wallet"), QString(),215//: Name of the wallet data file format.216tr("Wallet Data") + QLatin1String(" (*.dat)"), nullptr);218if (filename.isEmpty())219return;221if (!walletModel->wallet().backupWallet(filename.toLocal8Bit().data())) {222Q_EMIT message(tr("Backup Failed"), tr("There was an error trying to save the wallet data to %1.").arg(filename),223CClientUIInterface::MSG_ERROR);224}225else {226Q_EMIT message(tr("Backup Successful"), tr("The wallet data was successfully saved to %1.").arg(filename),227CClientUIInterface::MSG_INFORMATION);228}229}231void WalletView::changePassphrase()232{233auto dlg = new AskPassphraseDialog(AskPassphraseDialog::ChangePass, this);234dlg->setModel(walletModel);235GUIUtil::ShowModalDialogAsynchronously(dlg);236}238void WalletView::unlockWallet()239{240// Unlock wallet when requested by wallet model241if (walletModel->getEncryptionStatus() == WalletModel::Locked) {242AskPassphraseDialog dlg(AskPassphraseDialog::Unlock, this);243dlg.setModel(walletModel);244// A modal dialog must be synchronous here as expected245// in the WalletModel::requestUnlock() function.246dlg.exec();247}248}250void WalletView::usedSendingAddresses()
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.