81 for (
const auto& address :
wallet.getAddresses())
83 if (pk_hash_only && !std::holds_alternative<PKHash>(address.dest)) {
87 address.purpose, address.is_mine);
89 QString::fromStdString(address.name),
102 QList<AddressTableEntry>::iterator lower = std::lower_bound(
104 QList<AddressTableEntry>::iterator upper = std::upper_bound(
108 bool inModel = (lower != upper);
116 qWarning() <<
"AddressTablePriv::updateEntry: Warning: Got CT_NEW, but entry is already in model";
119 parent->beginInsertRows(QModelIndex(), lowerIndex, lowerIndex);
126 qWarning() <<
"AddressTablePriv::updateEntry: Warning: Got CT_UPDATED, but entry is not in model";
129 lower->type = newEntryType;
130 lower->label = label;
136 qWarning() <<
"AddressTablePriv::updateEntry: Warning: Got CT_DELETED, but entry is not in model";
139 parent->beginRemoveRows(QModelIndex(), lowerIndex, upperIndex-1);
165 QAbstractTableModel(parent), walletModel(parent)
167 columns << tr(
"Label") << tr(
"Address");
179 if (parent.isValid()) {
187 if (parent.isValid()) {
201 if (role == Qt::DisplayRole || role == Qt::EditRole) {
204 if (rec->
label.isEmpty() && role == Qt::DisplayRole) {
205 return tr(
"(no label)");
213 }
else if (role == Qt::FontRole) {
244 if(role == Qt::EditRole)
250 if(rec->
label == value.toString())
259 if(std::get_if<CNoDestination>(&newAddress))
265 else if(newAddress == curAddress)
273 newAddress,
nullptr,
nullptr,
nullptr))
294 if(orientation == Qt::Horizontal)
296 if(role == Qt::DisplayRole && section <
columns.size())
306 if (!
index.isValid())
return Qt::NoItemFlags;
310 Qt::ItemFlags retval = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
316 retval |= Qt::ItemIsEditable;
327 return createIndex(row, column,
priv->
index(row));
331 return QModelIndex();
344 std::string strLabel = label.toStdString();
345 std::string strAddress = address.toStdString();
393 return QString::fromStdString(strAddress);
414 return QString::fromStdString(
name);
437 QModelIndexList lst = match(
index(0,
Address, QModelIndex()),
438 Qt::EditRole, address, 1, Qt::MatchExactly);
445 return lst.at(0).row();
453 Q_EMIT dataChanged(
index(idx, 0, QModelIndex()),
index(idx,
columns.length()-1, QModelIndex()));
constexpr AddressTableEntry::Type translateTransactionType(wallet::AddressPurpose purpose, bool isMine)
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
Qt model of the address book in the core.
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
@ TypeRole
Type of address (Send or Receive)
int lookupAddress(const QString &address) const
OutputType GetDefaultAddressType() const
@ WALLET_UNLOCK_FAILURE
Wallet could not be unlocked to create new receiving address.
@ NO_CHANGES
No changes were made during edit operation.
@ INVALID_ADDRESS
Unparseable address.
@ KEY_GENERATION_FAILURE
Generating a new public key for a receiving address failed.
@ DUPLICATE_ADDRESS
Address already in address book.
void emitDataChanged(int index)
Notify listeners that data changed.
@ Address
Bitcoin address.
@ Label
User specified label.
QVariant data(const QModelIndex &index, int role) const override
QModelIndex index(int row, int column, const QModelIndex &parent) const override
std::optional< wallet::AddressPurpose > purposeForAddress(const QString &address) const
Look up purpose for address in address book, if not found return empty string.
AddressTableModel(WalletModel *parent=nullptr, bool pk_hash_only=false)
bool getAddressData(const QString &address, std::string *name, wallet::AddressPurpose *purpose) const
Look up address book data given an address string.
int columnCount(const QModelIndex &parent) const override
bool setData(const QModelIndex &index, const QVariant &value, int role) override
static const QString Send
Specifies send address.
void updateEntry(const QString &address, const QString &label, bool isMine, wallet::AddressPurpose purpose, int status)
QString addRow(const QString &type, const QString &label, const QString &address, const OutputType address_type)
friend class AddressTablePriv
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
QString GetWalletDisplayName() const
Qt::ItemFlags flags(const QModelIndex &index) const override
static const QString Receive
Specifies receive address.
int rowCount(const QModelIndex &parent) const override
WalletModel *const walletModel
QString labelForAddress(const QString &address) const
Look up label for address in address book, if not found return empty string.
QList< AddressTableEntry > cachedAddressTable
void updateEntry(const QString &address, const QString &label, bool isMine, wallet::AddressPurpose purpose, int status)
AddressTablePriv(AddressTableModel *_parent)
AddressTableEntry * index(int idx)
void refreshAddressTable(interfaces::Wallet &wallet, bool pk_hash_only=false)
AddressTableModel * parent
Interface to Bitcoin wallet from Qt view code.
bool validateAddress(const QString &address) const
interfaces::Wallet & wallet() const
QString getDisplayName() const
UnlockContext requestUnlock()
Interface for accessing a wallet.
virtual bool getAddress(const CTxDestination &dest, std::string *name, wallet::isminetype *is_mine, wallet::AddressPurpose *purpose)=0
Look up address in wallet, return whether exists.
virtual bool setAddressBook(const CTxDestination &dest, const std::string &name, const std::optional< wallet::AddressPurpose > &purpose)=0
Add or update address.
virtual OutputType getDefaultAddressType()=0
virtual bool delAddressBook(const CTxDestination &dest)=0
CTxDestination DecodeDestination(const std::string &str, std::string &error_msg, std::vector< int > *error_locations)
std::string EncodeDestination(const CTxDestination &dest)
QFont fixedPitchFont(bool use_embedded_font)
AddressPurpose
Address purpose field that has been been stored with wallet sending and receiving addresses since BIP...
@ REFUND
Never set in current code may be present in older wallet databases.
CTxDestination getNewDestination(CWallet &w, OutputType output_type)
Returns a new destination, of an specific type, from the wallet.
AddressTableEntry()=default
AddressTableEntry(Type _type, const QString &_label, const QString &_address)
bool operator()(const AddressTableEntry &a, const AddressTableEntry &b) const
bool operator()(const QString &a, const AddressTableEntry &b) const
bool operator()(const AddressTableEntry &a, const QString &b) const
is a home for public enum and struct type definitions that are used by internally by wallet code,...