Skip to content

Commit 3ec033e

Browse files
committed
Merge #121: Early subscribe core signals in transaction table model
cafef08 qt: Refactor to remove unnecessary block in DispatchNotifications (João Barbosa) 57785fb qt: Early subscribe core signals in transaction table model (João Barbosa) c6cbdf1 qt: Refactor ShowProgress to DispatchNotifications (João Barbosa) 3bccd50 qt: Set flag after inital load on transaction table model (João Barbosa) Pull request description: This fixes the case where transaction notifications arrive between `getWalletTxs` and `subscribeToCoreSignals`. Basically notifications are queued until `getWalletTxs` and wallet rescan complete. This is also a requirement to call `getWalletTxs` in a background thread. Motivated by bitcoin/bitcoin#20241. ACKs for top commit: jonatack: tACK cafef08 ryanofsky: Code review ACK cafef08. Only change since last review is splitting commits and replacing m_progress with m_loading. meshcollider: Code review ACK cafef08 Tree-SHA512: 003caab2f2ae3522619711c8d02d521d2b8f7f280a467f6c3d08abf37ca81cc66b4b9fa10acfdf34e5fe250da7b696cfeec435f72b53c1ea97ccda96d8b4be33
2 parents 707ba86 + cafef08 commit 3ec033e

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

src/qt/transactiontablemodel.cpp

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -96,25 +96,29 @@ class TransactionTablePriv
9696
*/
9797
QList<TransactionRecord> cachedWallet;
9898

99-
bool fQueueNotifications = false;
99+
/** True when model finishes loading all wallet transactions on start */
100+
bool m_loaded = false;
101+
/** True when transactions are being notified, for instance when scanning */
102+
bool m_loading = false;
100103
std::vector< TransactionNotification > vQueueNotifications;
101104

102105
void NotifyTransactionChanged(const uint256 &hash, ChangeType status);
103-
void ShowProgress(const std::string &title, int nProgress);
106+
void DispatchNotifications();
104107

105108
/* Query entire wallet anew from core.
106109
*/
107110
void refreshWallet(interfaces::Wallet& wallet)
108111
{
109-
qDebug() << "TransactionTablePriv::refreshWallet";
110-
cachedWallet.clear();
112+
assert(!m_loaded);
111113
{
112114
for (const auto& wtx : wallet.getWalletTxs()) {
113115
if (TransactionRecord::showTransaction()) {
114116
cachedWallet.append(TransactionRecord::decomposeTransaction(wtx));
115117
}
116118
}
117119
}
120+
m_loaded = true;
121+
DispatchNotifications();
118122
}
119123

120124
/* Update our model of the wallet incrementally, to synchronize our model of the wallet
@@ -249,12 +253,12 @@ TransactionTableModel::TransactionTableModel(const PlatformStyle *_platformStyle
249253
fProcessingQueuedTransactions(false),
250254
platformStyle(_platformStyle)
251255
{
256+
subscribeToCoreSignals();
257+
252258
columns << QString() << QString() << tr("Date") << tr("Type") << tr("Label") << BitcoinUnits::getAmountColumnTitle(walletModel->getOptionsModel()->getDisplayUnit());
253259
priv->refreshWallet(walletModel->wallet());
254260

255261
connect(walletModel->getOptionsModel(), &OptionsModel::displayUnitChanged, this, &TransactionTableModel::updateDisplayUnit);
256-
257-
subscribeToCoreSignals();
258262
}
259263

260264
TransactionTableModel::~TransactionTableModel()
@@ -719,44 +723,42 @@ void TransactionTablePriv::NotifyTransactionChanged(const uint256 &hash, ChangeT
719723

720724
TransactionNotification notification(hash, status, showTransaction);
721725

722-
if (fQueueNotifications)
726+
if (!m_loaded || m_loading)
723727
{
724728
vQueueNotifications.push_back(notification);
725729
return;
726730
}
727731
notification.invoke(parent);
728732
}
729733

730-
void TransactionTablePriv::ShowProgress(const std::string &title, int nProgress)
734+
void TransactionTablePriv::DispatchNotifications()
731735
{
732-
if (nProgress == 0)
733-
fQueueNotifications = true;
736+
if (!m_loaded || m_loading) return;
734737

735-
if (nProgress == 100)
738+
if (vQueueNotifications.size() > 10) { // prevent balloon spam, show maximum 10 balloons
739+
bool invoked = QMetaObject::invokeMethod(parent, "setProcessingQueuedTransactions", Qt::QueuedConnection, Q_ARG(bool, true));
740+
assert(invoked);
741+
}
742+
for (unsigned int i = 0; i < vQueueNotifications.size(); ++i)
736743
{
737-
fQueueNotifications = false;
738-
if (vQueueNotifications.size() > 10) { // prevent balloon spam, show maximum 10 balloons
739-
bool invoked = QMetaObject::invokeMethod(parent, "setProcessingQueuedTransactions", Qt::QueuedConnection, Q_ARG(bool, true));
744+
if (vQueueNotifications.size() - i <= 10) {
745+
bool invoked = QMetaObject::invokeMethod(parent, "setProcessingQueuedTransactions", Qt::QueuedConnection, Q_ARG(bool, false));
740746
assert(invoked);
741747
}
742-
for (unsigned int i = 0; i < vQueueNotifications.size(); ++i)
743-
{
744-
if (vQueueNotifications.size() - i <= 10) {
745-
bool invoked = QMetaObject::invokeMethod(parent, "setProcessingQueuedTransactions", Qt::QueuedConnection, Q_ARG(bool, false));
746-
assert(invoked);
747-
}
748748

749-
vQueueNotifications[i].invoke(parent);
750-
}
751-
vQueueNotifications.clear();
749+
vQueueNotifications[i].invoke(parent);
752750
}
751+
vQueueNotifications.clear();
753752
}
754753

755754
void TransactionTableModel::subscribeToCoreSignals()
756755
{
757756
// Connect signals to wallet
758757
m_handler_transaction_changed = walletModel->wallet().handleTransactionChanged(std::bind(&TransactionTablePriv::NotifyTransactionChanged, priv, std::placeholders::_1, std::placeholders::_2));
759-
m_handler_show_progress = walletModel->wallet().handleShowProgress(std::bind(&TransactionTablePriv::ShowProgress, priv, std::placeholders::_1, std::placeholders::_2));
758+
m_handler_show_progress = walletModel->wallet().handleShowProgress([this](const std::string&, int progress) {
759+
priv->m_loading = progress < 100;
760+
priv->DispatchNotifications();
761+
});
760762
}
761763

762764
void TransactionTableModel::unsubscribeFromCoreSignals()

0 commit comments

Comments
 (0)