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.
251{252editStatus = NO_CHANGES;253return false;254}255walletModel->wallet().setAddressBook(curAddress, value.toString().toStdString(), purpose);256} else if(index.column() == Address) {257CTxDestination newAddress = DecodeDestination(value.toString().toStdString());258// Refuse to set invalid address, set error status and return false259if(std::get_if<CNoDestination>(&newAddress))260{261editStatus = INVALID_ADDRESS;262return false;263}264// Do nothing, if old address == new address265else if(newAddress == curAddress)266{267editStatus = NO_CHANGES;268return false;269}270// Check for duplicate addresses to prevent accidental deletion of addresses, if you try271// to paste an existing address over another address (with a different label)272if (walletModel->wallet().getAddress(273newAddress, /*name=*/nullptr, /*purpose=*/ nullptr))274{275editStatus = DUPLICATE_ADDRESS;276return false;277}278// Double-check that we're not overwriting a receiving address279else if(rec->type == AddressTableEntry::Sending)280{281// Remove old entry282walletModel->wallet().delAddressBook(curAddress);283// Add new entry with new address284walletModel->wallet().setAddressBook(newAddress, value.toString().toStdString(), purpose);285}286}287return true;288}289return false;290}292QVariant AddressTableModel::headerData(int section, Qt::Orientation orientation, int role) const293{294if(orientation == Qt::Horizontal)295{296if(role == Qt::DisplayRole && section < columns.size())297{298return columns[section];299}300}301return QVariant();302}304Qt::ItemFlags AddressTableModel::flags(const QModelIndex &index) const305{306if (!index.isValid()) return Qt::NoItemFlags;308AddressTableEntry *rec = static_cast<AddressTableEntry*>(index.internalPointer());310Qt::ItemFlags retval = Qt::ItemIsSelectable | Qt::ItemIsEnabled;311// Can edit address and label for sending addresses,312// and only label for receiving addresses.313if(rec->type == AddressTableEntry::Sending ||314(rec->type == AddressTableEntry::Receiving && index.column()==Label))315{316retval |= Qt::ItemIsEditable;317}318return retval;319}321QModelIndex AddressTableModel::index(int row, int column, const QModelIndex &parent) const322{323Q_UNUSED(parent);324AddressTableEntry *data = priv->index(row);325if(data)326{327return createIndex(row, column, priv->index(row));328}329else330{331return QModelIndex();332}333}335void AddressTableModel::updateEntry(const QString &address,336const QString &label, bool isMine, wallet::AddressPurpose purpose, int status)337{338// Update address book model from Bitcoin core339priv->updateEntry(address, label, isMine, purpose, status);340}342QString AddressTableModel::addRow(const QString &type, const QString &label, const QString &address, const OutputType address_type)343{344std::string strLabel = label.toStdString();345std::string strAddress = address.toStdString();347editStatus = OK;349if(type == Send)350{351if(!walletModel->validateAddress(address))352{353editStatus = INVALID_ADDRESS;354return QString();355}356// Check for duplicate addresses357{358if (walletModel->wallet().getAddress(359DecodeDestination(strAddress), /*name=*/nullptr, /*purpose=*/nullptr))360{361editStatus = DUPLICATE_ADDRESS;362return QString();363}364}366// Add entry367walletModel->wallet().setAddressBook(DecodeDestination(strAddress), strLabel, wallet::AddressPurpose::SEND);368}369else if(type == Receive)370{371// Generate a new address to associate with given label372if (auto dest{walletModel->wallet().getNewDestination(address_type, strLabel)}) {373strAddress = EncodeDestination(*dest);374} else {375WalletModel::UnlockContext ctx(walletModel->requestUnlock());376if (!ctx.isValid()) {377// Unlock wallet failed or was cancelled378editStatus = WALLET_UNLOCK_FAILURE;379return QString();380}381if (auto dest_retry{walletModel->wallet().getNewDestination(address_type, strLabel)}) {382strAddress = EncodeDestination(*dest_retry);383} else {384editStatus = KEY_GENERATION_FAILURE;385return QString();386}387}388}389else390{391return QString();392}393return QString::fromStdString(strAddress);394}396bool AddressTableModel::removeRows(int row, int count, const QModelIndex &parent)397{398Q_UNUSED(parent);399AddressTableEntry *rec = priv->index(row);400if(count != 1 || !rec || rec->type == AddressTableEntry::Receiving)401{402// Can only remove one row at a time, and cannot remove rows not in model.403// Also refuse to remove receiving addresses.404return false;405}406walletModel->wallet().delAddressBook(DecodeDestination(rec->address.toStdString()));407return true;408}410QString AddressTableModel::labelForAddress(const QString &address) const411{412std::string name;413if (getAddressData(address, &name, /* purpose= */ nullptr)) {414return QString::fromStdString(name);415}416return QString();417}419std::optional<wallet::AddressPurpose> AddressTableModel::purposeForAddress(const QString &address) const420{421wallet::AddressPurpose purpose;422if (getAddressData(address, /* name= */ nullptr, &purpose)) {423return purpose;424}425return std::nullopt;426}428bool AddressTableModel::getAddressData(const QString &address,429std::string* name,430wallet::AddressPurpose* purpose) const {431CTxDestination destination = DecodeDestination(address.toStdString());432return walletModel->wallet().getAddress(destination, name, purpose);433}435int AddressTableModel::lookupAddress(const QString &address) const436{437QModelIndexList lst = match(index(0, Address, QModelIndex()),438Qt::EditRole, address, 1, Qt::MatchExactly);439if(lst.isEmpty())440{441return -1;442}443else444{445return lst.at(0).row();446}447}449OutputType AddressTableModel::GetDefaultAddressType() const { return walletModel->wallet().getDefaultAddressType(); };451void AddressTableModel::emitDataChanged(int idx)452{453Q_EMIT dataChanged(index(idx, 0, QModelIndex()), index(idx, columns.length()-1, QModelIndex()));454}456QString AddressTableModel::GetWalletDisplayName() const { return walletModel->getDisplayName(); };
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.