Skip to content

Commit f8e385a

Browse files
hebastoryanofsky
andcommitted
qt: Fix regression in TransactionTableModel
Since #17993 a crash is possible on exit. Co-authored-by: Russell Yanofsky <[email protected]>
1 parent dbd7a91 commit f8e385a

4 files changed

+11
-3
lines changed

src/qt/transactionrecord.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ void TransactionRecord::updateStatus(const interfaces::WalletTxStatus& wtx, cons
234234

235235
bool TransactionRecord::statusUpdateNeeded(const uint256& block_hash) const
236236
{
237-
return status.m_cur_block_hash != block_hash || status.needsUpdate;
237+
return (!block_hash.IsNull() && status.m_cur_block_hash != block_hash) || status.needsUpdate;
238238
}
239239

240240
QString TransactionRecord::getTxHash() const

src/qt/transactiontablemodel.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ QVariant TransactionTableModel::headerData(int section, Qt::Orientation orientat
664664
QModelIndex TransactionTableModel::index(int row, int column, const QModelIndex &parent) const
665665
{
666666
Q_UNUSED(parent);
667-
TransactionRecord* data = priv->index(walletModel->wallet(), walletModel->clientModel().getBestBlockHash(), row);
667+
TransactionRecord* data = priv->index(walletModel->wallet(), walletModel->getLastBlockProcessed(), row);
668668
if(data)
669669
{
670670
return createIndex(row, column, data);

src/qt/walletmodel.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void WalletModel::pollBalanceChanged()
8787
{
8888
// Avoid recomputing wallet balances unless a TransactionChanged or
8989
// BlockTip notification was received.
90-
if (!fForceCheckBalanceChanged && m_cached_last_update_tip == m_client_model->getBestBlockHash()) return;
90+
if (!fForceCheckBalanceChanged && m_cached_last_update_tip == getLastBlockProcessed()) return;
9191

9292
// Try to get balances and return early if locks can't be acquired. This
9393
// avoids the GUI from getting stuck on periodical polls if the core is
@@ -588,3 +588,8 @@ void WalletModel::refresh(bool pk_hash_only)
588588
{
589589
addressTableModel = new AddressTableModel(this, pk_hash_only);
590590
}
591+
592+
uint256 WalletModel::getLastBlockProcessed() const
593+
{
594+
return m_client_model ? m_client_model->getBestBlockHash() : uint256{};
595+
}

src/qt/walletmodel.h

+3
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ class WalletModel : public QObject
155155
AddressTableModel* getAddressTableModel() const { return addressTableModel; }
156156

157157
void refresh(bool pk_hash_only = false);
158+
159+
uint256 getLastBlockProcessed() const;
160+
158161
private:
159162
std::unique_ptr<interfaces::Wallet> m_wallet;
160163
std::unique_ptr<interfaces::Handler> m_handler_unload;

0 commit comments

Comments
 (0)