Changeset View
Changeset View
Standalone View
Standalone View
src/qt/walletmodel.cpp
Show All 28 Lines | |||||
WalletModel::WalletModel(std::unique_ptr<interfaces::Wallet> wallet, | WalletModel::WalletModel(std::unique_ptr<interfaces::Wallet> wallet, | ||||
ClientModel &client_model, | ClientModel &client_model, | ||||
const PlatformStyle *platformStyle, QObject *parent) | const PlatformStyle *platformStyle, QObject *parent) | ||||
: QObject(parent), m_wallet(std::move(wallet)), | : QObject(parent), m_wallet(std::move(wallet)), | ||||
m_client_model(&client_model), m_node(client_model.node()), | m_client_model(&client_model), m_node(client_model.node()), | ||||
optionsModel(client_model.getOptionsModel()), addressTableModel(nullptr), | optionsModel(client_model.getOptionsModel()), addressTableModel(nullptr), | ||||
transactionTableModel(nullptr), recentRequestsTableModel(nullptr), | transactionTableModel(nullptr), recentRequestsTableModel(nullptr), | ||||
cachedEncryptionStatus(Unencrypted), cachedNumBlocks(0), | cachedEncryptionStatus(Unencrypted), timer(new QTimer(this)) { | ||||
timer(new QTimer(this)) { | |||||
fHaveWatchOnly = m_wallet->haveWatchOnly(); | fHaveWatchOnly = m_wallet->haveWatchOnly(); | ||||
addressTableModel = new AddressTableModel(this); | addressTableModel = new AddressTableModel(this); | ||||
transactionTableModel = new TransactionTableModel(platformStyle, this); | transactionTableModel = new TransactionTableModel(platformStyle, this); | ||||
recentRequestsTableModel = new RecentRequestsTableModel(this); | recentRequestsTableModel = new RecentRequestsTableModel(this); | ||||
subscribeToCoreSignals(); | subscribeToCoreSignals(); | ||||
} | } | ||||
Show All 21 Lines | if (cachedEncryptionStatus != newEncryptionStatus) { | ||||
Q_EMIT encryptionStatusChanged(); | Q_EMIT encryptionStatusChanged(); | ||||
} | } | ||||
} | } | ||||
void WalletModel::pollBalanceChanged() { | void WalletModel::pollBalanceChanged() { | ||||
// Avoid recomputing wallet balances unless a TransactionChanged or | // Avoid recomputing wallet balances unless a TransactionChanged or | ||||
// BlockTip notification was received. | // BlockTip notification was received. | ||||
if (!fForceCheckBalanceChanged && | if (!fForceCheckBalanceChanged && | ||||
cachedNumBlocks == m_client_model->getNumBlocks()) { | m_cached_last_update_tip == m_client_model->getBestBlockHash()) { | ||||
return; | return; | ||||
} | } | ||||
// Try to get balances and return early if locks can't be acquired. This | // Try to get balances and return early if locks can't be acquired. This | ||||
// avoids the GUI from getting stuck on periodical polls if the core is | // avoids the GUI from getting stuck on periodical polls if the core is | ||||
// holding the locks for a longer time - for example, during a wallet | // holding the locks for a longer time - for example, during a wallet | ||||
// rescan. | // rescan. | ||||
interfaces::WalletBalances new_balances; | interfaces::WalletBalances new_balances; | ||||
int numBlocks = -1; | BlockHash block_hash; | ||||
if (!m_wallet->tryGetBalances(new_balances, numBlocks)) { | if (!m_wallet->tryGetBalances(new_balances, block_hash)) { | ||||
return; | return; | ||||
} | } | ||||
if (fForceCheckBalanceChanged || numBlocks != cachedNumBlocks) { | if (fForceCheckBalanceChanged || block_hash != m_cached_last_update_tip) { | ||||
fForceCheckBalanceChanged = false; | fForceCheckBalanceChanged = false; | ||||
// Balance and number of transactions might have changed | // Balance and number of transactions might have changed | ||||
cachedNumBlocks = numBlocks; | m_cached_last_update_tip = block_hash; | ||||
checkBalanceChanged(new_balances); | checkBalanceChanged(new_balances); | ||||
if (transactionTableModel) { | if (transactionTableModel) { | ||||
transactionTableModel->updateConfirmations(); | transactionTableModel->updateConfirmations(); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 432 Lines • Show Last 20 Lines |