36 const QString &_address)
59 if (strPurpose ==
"send") {
61 }
else if (strPurpose ==
"receive") {
63 }
else if (strPurpose ==
"unknown" || strPurpose ==
"") {
81 for (
const auto &address :
wallet.getAddresses()) {
83 QString::fromStdString(address.purpose), address.is_mine);
85 addressType, QString::fromStdString(address.name),
97 void updateEntry(
const QString &address,
const QString &label,
bool isMine,
98 const QString &purpose,
int status) {
100 QList<AddressTableEntry>::iterator lower = std::lower_bound(
103 QList<AddressTableEntry>::iterator upper = std::upper_bound(
108 bool inModel = (lower != upper);
115 qWarning() <<
"AddressTablePriv::updateEntry: Warning: Got "
116 "CT_NEW, but entry is already in model";
119 parent->beginInsertRows(QModelIndex(), lowerIndex, lowerIndex);
127 qWarning() <<
"AddressTablePriv::updateEntry: Warning: Got "
128 "CT_UPDATED, but entry is not in model";
131 lower->type = newEntryType;
132 lower->label = label;
137 qWarning() <<
"AddressTablePriv::updateEntry: Warning: Got "
138 "CT_DELETED, but entry is not in model";
141 parent->beginRemoveRows(QModelIndex(), lowerIndex,
161 : QAbstractTableModel(parent), walletModel(parent) {
162 columns << tr(
"Label") << tr(
"Address");
182 if (!
index.isValid()) {
189 if (role == Qt::DisplayRole || role == Qt::EditRole) {
190 switch (
index.column()) {
192 if (rec->
label.isEmpty() && role == Qt::DisplayRole) {
193 return tr(
"(no label)");
200 }
else if (role == Qt::FontRole) {
221 if (!
index.isValid()) {
226 std::string strPurpose =
230 if (role == Qt::EditRole) {
235 if (rec->
label == value.toString()) {
240 curAddress, value.toString().toStdString(), strPurpose);
245 if (std::get_if<CNoDestination>(&newAddress)) {
250 else if (newAddress == curAddress) {
258 newAddress,
nullptr,
nullptr,
269 newAddress, value.toString().toStdString(), strPurpose);
279 if (orientation == Qt::Horizontal) {
280 if (role == Qt::DisplayRole && section <
columns.size()) {
288 if (!
index.isValid()) {
289 return Qt::NoItemFlags;
294 Qt::ItemFlags retval = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
300 retval |= Qt::ItemIsEditable;
306 const QModelIndex &parent)
const {
310 return createIndex(row, column,
priv->
index(row));
312 return QModelIndex();
317 const QString &label,
bool isMine,
318 const QString &purpose,
int status) {
324 const QString &address,
326 std::string strLabel = label.toStdString();
327 std::string strAddress = address.toStdString();
354 if (!
ctx.isValid()) {
369 return QString::fromStdString(strAddress);
373 const QModelIndex &parent) {
390 return QString::fromStdString(
name);
398 return QString::fromStdString(purpose);
405 std::string *purpose)
const {
413 QModelIndexList lst = match(
index(0,
Address, QModelIndex()), Qt::EditRole,
414 address, 1, Qt::MatchExactly);
418 return lst.at(0).row();
427 Q_EMIT dataChanged(
index(idx, 0, QModelIndex()),
static AddressTableEntry::Type translateTransactionType(const QString &strPurpose, bool isMine)
std::string EncodeCashAddr(const CTxDestination &dst, const CChainParams ¶ms)
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
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.
QString addRow(const QString &type, const QString &label, const QString &address, const OutputType address_type)
void updateEntry(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
friend class AddressTablePriv
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
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
AddressTableModel(WalletModel *parent=nullptr)
QString purposeForAddress(const QString &address) const
Look up purpose for address in address book, if not found return empty string.
QString labelForAddress(const QString &address) const
Look up label for address in address book, if not found return empty string.
bool getAddressData(const QString &address, std::string *name, std::string *purpose) const
Look up address book data given an address string.
QList< AddressTableEntry > cachedAddressTable
AddressTablePriv(AddressTableModel *_parent)
void updateEntry(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
AddressTableEntry * index(int idx)
void refreshAddressTable(interfaces::Wallet &wallet)
AddressTableModel * parent
Interface to Bitcoin wallet from Qt view code.
bool validateAddress(const QString &address)
const CChainParams & getChainParams() const
interfaces::Wallet & wallet() const
UnlockContext requestUnlock()
Interface for accessing a wallet.
virtual bool getNewDestination(const OutputType type, const std::string label, CTxDestination &dest)=0
virtual bool setAddressBook(const CTxDestination &dest, const std::string &name, const std::string &purpose)=0
Add or update address.
virtual OutputType getDefaultAddressType()=0
virtual bool delAddressBook(const CTxDestination &dest)=0
virtual bool getAddress(const CTxDestination &dest, std::string *name, isminetype *is_mine, std::string *purpose)=0
Look up address in wallet, return whether exists.
CTxDestination DecodeDestination(const std::string &addr, const CChainParams ¶ms)
std::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
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