Skip to content

Commit 3b44576

Browse files
committed
Hold and update label in TransactionRecord
Instead of looking it up in data()
1 parent bd205c0 commit 3b44576

File tree

5 files changed

+50
-2
lines changed

5 files changed

+50
-2
lines changed

src/qt/transactionrecord.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet *
254254
void TransactionRecord::updateStatus(const CWalletTx &wtx, int chainLockHeight)
255255
{
256256
AssertLockHeld(cs_main);
257+
AssertLockHeld(wtx.GetWallet()->cs_wallet);
257258
// Determine transaction status
258259

259260
// Find the block the tx is in
@@ -278,6 +279,13 @@ void TransactionRecord::updateStatus(const CWalletTx &wtx, int chainLockHeight)
278279
status.lockedByChainLocks = wtx.IsChainLocked();
279280
}
280281

282+
auto addrBookIt = wtx.GetWallet()->mapAddressBook.find(this->txDest);
283+
if (addrBookIt == wtx.GetWallet()->mapAddressBook.end()) {
284+
status.label = "";
285+
} else {
286+
status.label = QString::fromStdString(addrBookIt->second.name);
287+
}
288+
281289
if (!CheckFinalTx(wtx))
282290
{
283291
if (wtx.tx->nLockTime < LOCKTIME_THRESHOLD)

src/qt/transactionrecord.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ class TransactionStatus
5050
bool lockedByChainLocks;
5151
/// Sorting key based on status
5252
std::string sortKey;
53+
/// Label
54+
QString label;
5355

5456
/** @name Generated (mined) transactions
5557
@{*/

src/qt/transactiontablemodel.cpp

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,19 @@ class TransactionTablePriv
176176
}
177177
}
178178

179+
void updateAddressBook(const QString& address, const QString& label, bool isMine, const QString& purpose, int status)
180+
{
181+
std::string address2 = address.toStdString();
182+
int index = 0;
183+
for (auto& rec : cachedWallet) {
184+
if (rec.strAddress == address2) {
185+
rec.status.needsUpdate = true;
186+
Q_EMIT parent->dataChanged(parent->index(index, TransactionTableModel::Status), parent->index(index, TransactionTableModel::Status));
187+
}
188+
index++;
189+
}
190+
}
191+
179192
int size()
180193
{
181194
return cachedWallet.size();
@@ -276,6 +289,12 @@ void TransactionTableModel::updateTransaction(const QString &hash, int status, b
276289
priv->updateWallet(updated, status, showTransaction);
277290
}
278291

292+
void TransactionTableModel::updateAddressBook(const QString& address, const QString& label, bool isMine,
293+
const QString& purpose, int status)
294+
{
295+
priv->updateAddressBook(address, label, isMine, purpose, status);
296+
}
297+
279298
void TransactionTableModel::updateConfirmations()
280299
{
281300
// Blocks came in since last poll.
@@ -669,7 +688,7 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const
669688
case AddressRole:
670689
return QString::fromStdString(rec->strAddress);
671690
case LabelRole:
672-
return walletModel->getAddressTableModel()->labelForDestination(rec->txDest);
691+
return rec->status.label;
673692
case AmountRole:
674693
return qint64(rec->credit + rec->debit);
675694
case TxIDRole:
@@ -681,7 +700,7 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const
681700
case TxPlainTextRole:
682701
{
683702
QString details;
684-
QString txLabel = walletModel->getAddressTableModel()->labelForDestination(rec->txDest);
703+
QString txLabel = rec->status.label;
685704

686705
details.append(formatTxDate(rec));
687706
details.append(" ");
@@ -813,6 +832,16 @@ static void NotifyTransactionChanged(TransactionTableModel *ttm, CWallet *wallet
813832
notification.invoke(ttm);
814833
}
815834

835+
static void NotifyAddressBookChanged(TransactionTableModel *ttm, CWallet *wallet, const CTxDestination &address, const std::string &label, bool isMine, const std::string &purpose, ChangeType status)
836+
{
837+
QMetaObject::invokeMethod(ttm, "updateAddressBook", Qt::QueuedConnection,
838+
Q_ARG(QString, QString::fromStdString(CBitcoinAddress(address).ToString())),
839+
Q_ARG(QString, QString::fromStdString(label)),
840+
Q_ARG(bool, isMine),
841+
Q_ARG(QString, QString::fromStdString(purpose)),
842+
Q_ARG(int, (int)status));
843+
}
844+
816845
static void ShowProgress(TransactionTableModel *ttm, const std::string &title, int nProgress)
817846
{
818847
if (nProgress == 0)
@@ -838,12 +867,14 @@ void TransactionTableModel::subscribeToCoreSignals()
838867
{
839868
// Connect signals to wallet
840869
wallet->NotifyTransactionChanged.connect(boost::bind(NotifyTransactionChanged, this, _1, _2, _3));
870+
wallet->NotifyAddressBookChanged.connect(boost::bind(NotifyAddressBookChanged, this, _1, _2, _3, _4, _5, _6));
841871
wallet->ShowProgress.connect(boost::bind(ShowProgress, this, _1, _2));
842872
}
843873

844874
void TransactionTableModel::unsubscribeFromCoreSignals()
845875
{
846876
// Disconnect signals from wallet
847877
wallet->NotifyTransactionChanged.disconnect(boost::bind(NotifyTransactionChanged, this, _1, _2, _3));
878+
wallet->NotifyAddressBookChanged.disconnect(boost::bind(NotifyAddressBookChanged, this, _1, _2, _3, _4, _5, _6));
848879
wallet->ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2));
849880
}

src/qt/transactiontablemodel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ class TransactionTableModel : public QAbstractTableModel
118118
public Q_SLOTS:
119119
/* New transaction, or transaction changed status */
120120
void updateTransaction(const QString &hash, int status, bool showTransaction);
121+
void updateAddressBook(const QString &address, const QString &label,
122+
bool isMine, const QString &purpose, int status);
121123
void updateConfirmations();
122124
void updateDisplayUnit();
123125
/** Updates the column title to "Amount (DisplayUnit)" and emits headerDataChanged() signal for table headers to react. */

src/wallet/wallet.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,11 @@ class CWalletTx : public CMerkleTx
484484
MarkDirty();
485485
}
486486

487+
const CWallet* GetWallet() const
488+
{
489+
return pwallet;
490+
}
491+
487492
//! filter decides which addresses will count towards the debit
488493
CAmount GetDebit(const isminefilter& filter) const;
489494
CAmount GetCredit(const isminefilter& filter) const;

0 commit comments

Comments
 (0)