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/sendcoinsentry.h>6#include <qt/forms/ui_sendcoinsentry.h>8#include <qt/addressbookpage.h>9#include <qt/addresstablemodel.h>10#include <qt/guiutil.h>11#include <qt/optionsmodel.h>12#include <qt/platformstyle.h>13#include <qt/walletmodel.h>15#include <QApplication>16#include <QClipboard>18SendCoinsEntry::SendCoinsEntry(const PlatformStyle *_platformStyle, QWidget *parent) :19QWidget(parent),20ui(new Ui::SendCoinsEntry),21platformStyle(_platformStyle)22{23ui->setupUi(this);25ui->addressBookButton->setIcon(platformStyle->SingleColorIcon(":/icons/address-book"));26ui->pasteButton->setIcon(platformStyle->SingleColorIcon(":/icons/editpaste"));27ui->deleteButton->setIcon(platformStyle->SingleColorIcon(":/icons/remove"));29if (platformStyle->getUseExtraSpacing())30ui->payToLayout->setSpacing(4);32GUIUtil::setupAddressWidget(ui->payTo, this);34// Connect signals35connect(ui->payAmount, &BitcoinAmountField::valueChanged, this, &SendCoinsEntry::payAmountChanged);36connect(ui->checkboxSubtractFeeFromAmount, &QCheckBox::toggled, this, &SendCoinsEntry::subtractFeeFromAmountChanged);37connect(ui->deleteButton, &QPushButton::clicked, this, &SendCoinsEntry::deleteClicked);38connect(ui->useAvailableBalanceButton, &QPushButton::clicked, this, &SendCoinsEntry::useAvailableBalanceClicked);39}41SendCoinsEntry::~SendCoinsEntry()42{43delete ui;44}46void SendCoinsEntry::on_pasteButton_clicked()47{48// Paste text from clipboard into recipient field49ui->payTo->setText(QApplication::clipboard()->text());50}52void SendCoinsEntry::on_addressBookButton_clicked()53{54if(!model)55return;56AddressBookPage dlg(platformStyle, AddressBookPage::ForSelection, AddressBookPage::SendingTab, this);57dlg.setModel(model->getAddressTableModel());58if(dlg.exec())59{60ui->payTo->setText(dlg.getReturnValue());61ui->payAmount->setFocus();62}63}65void SendCoinsEntry::on_payTo_textChanged(const QString &address)66{67updateLabel(address);68}70void SendCoinsEntry::setModel(WalletModel *_model)71{72this->model = _model;74if (_model && _model->getOptionsModel())75connect(_model->getOptionsModel(), &OptionsModel::displayUnitChanged, this, &SendCoinsEntry::updateDisplayUnit);77clear();78}80void SendCoinsEntry::clear()81{82// clear UI elements for normal payment83ui->payTo->clear();84ui->addAsLabel->clear();85ui->payAmount->clear();86if (model && model->getOptionsModel()) {87ui->checkboxSubtractFeeFromAmount->setChecked(model->getOptionsModel()->getSubFeeFromAmount());88}89ui->messageTextLabel->clear();90ui->messageTextLabel->hide();91ui->messageLabel->hide();93// update the display unit, to not use the default ("BTC")94updateDisplayUnit();95}97void SendCoinsEntry::checkSubtractFeeFromAmount()98{99ui->checkboxSubtractFeeFromAmount->setChecked(true);100}102void SendCoinsEntry::deleteClicked()103{104Q_EMIT removeEntry(this);105}107void SendCoinsEntry::useAvailableBalanceClicked()108{109Q_EMIT useAvailableBalance(this);110}112bool SendCoinsEntry::validate(interfaces::Node& node)113{114if (!model)115return false;117// Check input validity118bool retval = true;120if (!model->validateAddress(ui->payTo->text()))121{122ui->payTo->setValid(false);123retval = false;124}126if (!ui->payAmount->validate())127{128retval = false;129}131// Sending a zero amount is invalid132if (ui->payAmount->value(nullptr) <= 0)133{134ui->payAmount->setValid(false);135retval = false;136}138// Reject dust outputs:139if (retval && GUIUtil::isDust(node, ui->payTo->text(), ui->payAmount->value())) {140ui->payAmount->setValid(false);141retval = false;142}144return retval;145}147SendCoinsRecipient SendCoinsEntry::getValue()148{149recipient.address = ui->payTo->text();150recipient.label = ui->addAsLabel->text();151recipient.amount = ui->payAmount->value();152recipient.message = ui->messageTextLabel->text();153recipient.fSubtractFeeFromAmount = (ui->checkboxSubtractFeeFromAmount->checkState() == Qt::Checked);155return recipient;156}158QWidget *SendCoinsEntry::setupTabChain(QWidget *prev)159{160QWidget::setTabOrder(prev, ui->payTo);161QWidget::setTabOrder(ui->payTo, ui->addAsLabel);162QWidget *w = ui->payAmount->setupTabChain(ui->addAsLabel);163QWidget::setTabOrder(w, ui->checkboxSubtractFeeFromAmount);164QWidget::setTabOrder(ui->checkboxSubtractFeeFromAmount, ui->addressBookButton);165QWidget::setTabOrder(ui->addressBookButton, ui->pasteButton);166QWidget::setTabOrder(ui->pasteButton, ui->deleteButton);167return ui->deleteButton;168}170void SendCoinsEntry::setValue(const SendCoinsRecipient &value)171{172recipient = value;173{174// message175ui->messageTextLabel->setText(recipient.message);176ui->messageTextLabel->setVisible(!recipient.message.isEmpty());177ui->messageLabel->setVisible(!recipient.message.isEmpty());179ui->addAsLabel->clear();180ui->payTo->setText(recipient.address); // this may set a label from addressbook181if (!recipient.label.isEmpty()) // if a label had been set from the addressbook, don't overwrite with an empty label182ui->addAsLabel->setText(recipient.label);183ui->payAmount->setValue(recipient.amount);184}185}187void SendCoinsEntry::setAddress(const QString &address)188{189ui->payTo->setText(address);190ui->payAmount->setFocus();191}193void SendCoinsEntry::setAmount(const CAmount &amount)194{195ui->payAmount->setValue(amount);196}198bool SendCoinsEntry::isClear()199{200return ui->payTo->text().isEmpty();201}203void SendCoinsEntry::setFocus()204{205ui->payTo->setFocus();206}208void SendCoinsEntry::updateDisplayUnit()209{210if (model && model->getOptionsModel()) {211ui->payAmount->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());212}213}215void SendCoinsEntry::changeEvent(QEvent* e)216{217if (e->type() == QEvent::PaletteChange) {218ui->addressBookButton->setIcon(platformStyle->SingleColorIcon(QStringLiteral(":/icons/address-book")));219ui->pasteButton->setIcon(platformStyle->SingleColorIcon(QStringLiteral(":/icons/editpaste")));220ui->deleteButton->setIcon(platformStyle->SingleColorIcon(QStringLiteral(":/icons/remove")));221}223QWidget::changeEvent(e);224}226bool SendCoinsEntry::updateLabel(const QString &address)227{228if(!model)229return false;231// Fill in label from address book, if address has an associated label232QString associatedLabel = model->getAddressTableModel()->labelForAddress(address);233if(!associatedLabel.isEmpty())234{235ui->addAsLabel->setText(associatedLabel);236return true;237}239return false;240}242#include <moc_sendcoinsentry.cpp>
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.