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#ifndef BITCOIN_QT_ADDRESSTABLEMODEL_H6#define BITCOIN_QT_ADDRESSTABLEMODEL_H8#include <optional>10#include <QAbstractTableModel>11#include <QStringList>13enum class OutputType;15class AddressTablePriv;16class WalletModel;18namespace interfaces {19class Wallet;20}21namespace wallet {22enum class AddressPurpose;23} // namespace wallet25/**26Qt model of the address book in the core. This allows views to access and modify the address book.27*/28class AddressTableModel : public QAbstractTableModel29{30Q_OBJECT32public:33explicit AddressTableModel(WalletModel *parent = nullptr, bool pk_hash_only = false);34~AddressTableModel();36enum ColumnIndex {37Label = 0, /**< User specified label */38Address = 1 /**< Bitcoin address */39};41enum RoleIndex {42TypeRole = Qt::UserRole /**< Type of address (#Send or #Receive) */43};45/** Return status of edit/insert operation */46enum EditStatus {47OK, /**< Everything ok */48NO_CHANGES, /**< No changes were made during edit operation */49INVALID_ADDRESS, /**< Unparseable address */50DUPLICATE_ADDRESS, /**< Address already in address book */51WALLET_UNLOCK_FAILURE, /**< Wallet could not be unlocked to create new receiving address */52KEY_GENERATION_FAILURE /**< Generating a new public key for a receiving address failed */53};55static const QString Send; /**< Specifies send address */56static const QString Receive; /**< Specifies receive address */58/** @name Methods overridden from QAbstractTableModel59@{*/60int rowCount(const QModelIndex &parent) const override;61int columnCount(const QModelIndex &parent) const override;62QVariant data(const QModelIndex &index, int role) const override;63bool setData(const QModelIndex &index, const QVariant &value, int role) override;64QVariant headerData(int section, Qt::Orientation orientation, int role) const override;65QModelIndex index(int row, int column, const QModelIndex &parent) const override;66bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;67Qt::ItemFlags flags(const QModelIndex &index) const override;68/*@}*/70/* Add an address to the model.71Returns the added address on success, and an empty string otherwise.72*/73QString addRow(const QString& type, const QString& label, const QString& address, OutputType address_type);75/** Look up label for address in address book, if not found return empty string. */76QString labelForAddress(const QString &address) const;78/** Look up purpose for address in address book, if not found return empty string. */79std::optional<wallet::AddressPurpose> purposeForAddress(const QString &address) const;81/* Look up row index of an address in the model.82Return -1 if not found.83*/84int lookupAddress(const QString &address) const;86EditStatus getEditStatus() const { return editStatus; }88OutputType GetDefaultAddressType() const;90QString GetWalletDisplayName() const;92private:93WalletModel* const walletModel;94AddressTablePriv *priv = nullptr;95QStringList columns;96EditStatus editStatus = OK;98/** Look up address book data given an address string. */99bool getAddressData(const QString &address, std::string* name, wallet::AddressPurpose* purpose) const;101/** Notify listeners that data changed. */102void emitDataChanged(int index);104public Q_SLOTS:105/* Update address list from core.106*/107void updateEntry(const QString &address, const QString &label, bool isMine, wallet::AddressPurpose purpose, int status);109friend class AddressTablePriv;110};112#endif // BITCOIN_QT_ADDRESSTABLEMODEL_H
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.