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/editaddressdialog.h>6#include <qt/forms/ui_editaddressdialog.h>8#include <qt/addresstablemodel.h>9#include <qt/guiutil.h>11#include <wallet/types.h>13#include <QDataWidgetMapper>14#include <QMessageBox>17EditAddressDialog::EditAddressDialog(Mode _mode, QWidget* parent)18: QDialog(parent, GUIUtil::dialog_flags),19ui(new Ui::EditAddressDialog),20mode(_mode)21{22ui->setupUi(this);24GUIUtil::setupAddressWidget(ui->addressEdit, this);26switch(mode)27{28case NewSendingAddress:29setWindowTitle(tr("New sending address"));30break;31case EditReceivingAddress:32setWindowTitle(tr("Edit receiving address"));33ui->addressEdit->setEnabled(false);34break;35case EditSendingAddress:36setWindowTitle(tr("Edit sending address"));37break;38}40mapper = new QDataWidgetMapper(this);41mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);43GUIUtil::ItemDelegate* delegate = new GUIUtil::ItemDelegate(mapper);44connect(delegate, &GUIUtil::ItemDelegate::keyEscapePressed, this, &EditAddressDialog::reject);45mapper->setItemDelegate(delegate);47GUIUtil::handleCloseWindowShortcut(this);48}50EditAddressDialog::~EditAddressDialog()51{52delete ui;53}55void EditAddressDialog::setModel(AddressTableModel *_model)56{57this->model = _model;58if(!_model)59return;61mapper->setModel(_model);62mapper->addMapping(ui->labelEdit, AddressTableModel::Label);63mapper->addMapping(ui->addressEdit, AddressTableModel::Address);64}66void EditAddressDialog::loadRow(int row)67{68mapper->setCurrentIndex(row);69}71bool EditAddressDialog::saveCurrentRow()72{73if(!model)74return false;76switch(mode)77{78case NewSendingAddress:79address = model->addRow(80AddressTableModel::Send,81ui->labelEdit->text(),82ui->addressEdit->text(),83model->GetDefaultAddressType());84break;85case EditReceivingAddress:86case EditSendingAddress:87if(mapper->submit())88{89address = ui->addressEdit->text();90}91break;92}93return !address.isEmpty();94}96void EditAddressDialog::accept()97{98if(!model)99return;101if(!saveCurrentRow())102{103switch(model->getEditStatus())104{105case AddressTableModel::OK:106// Failed with unknown reason. Just reject.107break;108case AddressTableModel::NO_CHANGES:109// No changes were made during edit operation. Just reject.110break;111case AddressTableModel::INVALID_ADDRESS:112QMessageBox::warning(this, windowTitle(),113tr("The entered address \"%1\" is not a valid Bitcoin address.").arg(ui->addressEdit->text()),114QMessageBox::Ok, QMessageBox::Ok);115break;116case AddressTableModel::DUPLICATE_ADDRESS:117QMessageBox::warning(this, windowTitle(),118getDuplicateAddressWarning(),119QMessageBox::Ok, QMessageBox::Ok);120break;121case AddressTableModel::WALLET_UNLOCK_FAILURE:122QMessageBox::critical(this, windowTitle(),123tr("Could not unlock wallet."),124QMessageBox::Ok, QMessageBox::Ok);125break;126case AddressTableModel::KEY_GENERATION_FAILURE:127QMessageBox::critical(this, windowTitle(),128tr("New key generation failed."),129QMessageBox::Ok, QMessageBox::Ok);130break;132}133return;134}135QDialog::accept();136}138QString EditAddressDialog::getDuplicateAddressWarning() const139{140QString dup_address = ui->addressEdit->text();141QString existing_label = model->labelForAddress(dup_address);142auto existing_purpose = model->purposeForAddress(dup_address);144if (existing_purpose == wallet::AddressPurpose::RECEIVE &&145(mode == NewSendingAddress || mode == EditSendingAddress)) {146return tr(147"Address \"%1\" already exists as a receiving address with label "148"\"%2\" and so cannot be added as a sending address."149).arg(dup_address).arg(existing_label);150}151return tr(152"The entered address \"%1\" is already in the address book with "153"label \"%2\"."154).arg(dup_address).arg(existing_label);155}157QString EditAddressDialog::getAddress() const158{159return address;160}162void EditAddressDialog::setAddress(const QString &_address)163{164this->address = _address;165ui->addressEdit->setText(_address);166}
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.