36 type(_type), label(_label), address(_address) {}
60 if (strPurpose ==
"send")
62 else if (strPurpose ==
"receive")
64 else if (strPurpose ==
"unknown" || strPurpose ==
"")
81 cachedAddressTable.clear();
85 if (pk_hash_only && address.dest.type() !=
typeid(
PKHash))
88 QString::fromStdString(address.purpose), address.is_mine);
90 QString::fromStdString(address.name),
100 void updateEntry(
const QString &address,
const QString &label,
bool isMine,
const QString &purpose,
int status)
103 QList<AddressTableEntry>::iterator lower = std::lower_bound(
105 QList<AddressTableEntry>::iterator upper = std::upper_bound(
107 int lowerIndex = (lower - cachedAddressTable.begin());
108 int upperIndex = (upper - cachedAddressTable.begin());
109 bool inModel = (lower != upper);
117 qWarning() <<
"AddressTablePriv::updateEntry: Warning: Got CT_NEW, but entry is already in model";
120 parent->beginInsertRows(QModelIndex(), lowerIndex, lowerIndex);
121 cachedAddressTable.insert(lowerIndex,
AddressTableEntry(newEntryType, label, address));
122 parent->endInsertRows();
127 qWarning() <<
"AddressTablePriv::updateEntry: Warning: Got CT_UPDATED, but entry is not in model";
130 lower->type = newEntryType;
131 lower->label = label;
137 qWarning() <<
"AddressTablePriv::updateEntry: Warning: Got CT_DELETED, but entry is not in model";
140 parent->beginRemoveRows(QModelIndex(), lowerIndex, upperIndex-1);
141 cachedAddressTable.erase(lower, upper);
142 parent->endRemoveRows();
149 return cachedAddressTable.size();
154 if(idx >= 0 && idx < cachedAddressTable.size())
156 return &cachedAddressTable[idx];
166 QAbstractTableModel(parent), walletModel(parent)
168 columns << tr(
"Label") << tr(
"Address");
197 if(role == Qt::DisplayRole || role == Qt::EditRole)
199 switch(index.column())
202 if(rec->
label.isEmpty() && role == Qt::DisplayRole)
204 return tr(
"(no label)");
214 else if (role == Qt::FontRole)
245 if(role == Qt::EditRole)
248 if(index.column() ==
Label)
251 if(rec->
label == value.toString())
257 }
else if(index.column() ==
Address) {
260 if(boost::get<CNoDestination>(&newAddress))
266 else if(newAddress == curAddress)
274 newAddress,
nullptr,
nullptr,
nullptr))
295 if(orientation == Qt::Horizontal)
297 if(role == Qt::DisplayRole && section <
columns.size())
307 if (!index.isValid())
return Qt::NoItemFlags;
311 Qt::ItemFlags retval = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
317 retval |= Qt::ItemIsEditable;
328 return createIndex(row, column,
priv->
index(row));
332 return QModelIndex();
337 const QString &label,
bool isMine,
const QString &purpose,
int status)
345 std::string strLabel = label.toStdString();
346 std::string strAddress = address.toStdString();
395 return QString::fromStdString(strAddress);
416 return QString::fromStdString(name);
425 return QString::fromStdString(purpose);
432 std::string* purpose)
const {
439 QModelIndexList lst = match(
index(0,
Address, QModelIndex()),
440 Qt::EditRole, address, 1, Qt::MatchExactly);
447 return lst.at(0).row();
455 Q_EMIT dataChanged(
index(idx, 0, QModelIndex()),
index(idx,
columns.length()-1, QModelIndex()));
QVariant data(const QModelIndex &index, int role) const override
virtual bool getAddress(const CTxDestination &dest, std::string *name, isminetype *is_mine, std::string *purpose)=0
Look up address in wallet, return whether exists.
Generating a new public key for a receiving address failed.
bool operator()(const AddressTableEntry &a, const QString &b) const
virtual OutputType getDefaultAddressType()=0
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
int lookupAddress(const QString &address) const
UnlockContext requestUnlock()
AddressTableEntry * index(int idx)
Address already in address book.
int rowCount(const QModelIndex &parent) const override
interfaces::Wallet & wallet() const
QString addRow(const QString &type, const QString &label, const QString &address, const OutputType address_type)
static const QString Send
Specifies send address.
bool operator()(const AddressTableEntry &a, const AddressTableEntry &b) const
int columnCount(const QModelIndex &parent) const override
bool setData(const QModelIndex &index, const QVariant &value, int role) override
Wallet could not be unlocked to create new receiving address.
QList< AddressTableEntry > cachedAddressTable
Qt::ItemFlags flags(const QModelIndex &index) const override
bool operator()(const QString &a, const AddressTableEntry &b) const
static secp256k1_context * ctx
Interface for accessing a wallet.
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
AddressTableModel * parent
WalletModel *const walletModel
Qt model of the address book in the core.
AddressTablePriv(AddressTableModel *_parent)
AddressTableEntry(Type _type, const QString &_label, const QString &_address)
QString purposeForAddress(const QString &address) const
Look up purpose for address in address book, if not found return empty string.
bool validateAddress(const QString &address)
CTxDestination DecodeDestination(const std::string &str)
bool getAddressData(const QString &address, std::string *name, std::string *purpose) const
Look up address book data given an address string.
virtual bool getNewDestination(const OutputType type, const std::string label, CTxDestination &dest)=0
virtual bool delAddressBook(const CTxDestination &dest)=0
QString labelForAddress(const QString &address) const
Look up label for address in address book, if not found return empty string.
Interface to Bitcoin wallet from Qt view code.
void updateEntry(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
static const QString Receive
Specifies receive address.
void emitDataChanged(int index)
Notify listeners that data changed.
virtual bool setAddressBook(const CTxDestination &dest, const std::string &name, const std::string &purpose)=0
Add or update address.
OutputType GetDefaultAddressType() const
void refreshAddressTable(interfaces::Wallet &wallet, bool pk_hash_only=false)
std::string EncodeDestination(const CTxDestination &dest)
No changes were made during edit operation.
boost::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessUnknown > CTxDestination
A txout script template with a specific destination.
static AddressTableEntry::Type translateTransactionType(const QString &strPurpose, bool isMine)
friend class AddressTablePriv
QModelIndex index(int row, int column, const QModelIndex &parent) const override
void updateEntry(const QString &address, const QString &label, bool isMine, const QString &purpose, int status)
AddressTableModel(WalletModel *parent=nullptr, bool pk_hash_only=false)
Type of address (Send or Receive)
virtual std::vector< WalletAddress > getAddresses()=0
Get wallet address list.