aboutsummaryrefslogtreecommitdiff
path: root/src/qt/walletmodel.cpp
diff options
context:
space:
mode:
authorScott Ellis <sje397@gmail.com>2012-07-06 01:43:28 +1000
committerScott Ellis <sje397@gmail.com>2012-07-06 03:05:35 +1000
commit6c83a8419b3dd6aee2900803e2ee6e61781a16f8 (patch)
tree5ff5842ceb38f3e6ce934c6be47cdc2ad1257cd0 /src/qt/walletmodel.cpp
parentfe70b09c428585166f1040e9023251c9c250e894 (diff)
Add a timer to check for changes in immature or unconfirmed balances,
when these are non-zero. Fixed a minor mem leak.
Diffstat (limited to 'src/qt/walletmodel.cpp')
-rw-r--r--src/qt/walletmodel.cpp56
1 files changed, 43 insertions, 13 deletions
diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp
index 9245f774a4..0111e0cd91 100644
--- a/src/qt/walletmodel.cpp
+++ b/src/qt/walletmodel.cpp
@@ -10,17 +10,27 @@
#include "base58.h"
#include <QSet>
+#include <QTimer>
WalletModel::WalletModel(CWallet *wallet, OptionsModel *optionsModel, QObject *parent) :
QObject(parent), wallet(wallet), optionsModel(optionsModel), addressTableModel(0),
transactionTableModel(0),
cachedBalance(0), cachedUnconfirmedBalance(0), cachedImmatureBalance(0),
cachedNumTransactions(0),
- cachedEncryptionStatus(Unencrypted)
+ cachedEncryptionStatus(Unencrypted),
+ cachedNumBlocks(0)
{
addressTableModel = new AddressTableModel(wallet, this);
transactionTableModel = new TransactionTableModel(wallet, this);
+ // This single-shot timer will be fired from the 'checkBalancedChanged'
+ // method repeatedly while either of the unconfirmed or immature balances
+ // are non-zero
+ pollTimer = new QTimer(this);
+ pollTimer->setInterval(MODEL_UPDATE_DELAY);
+ pollTimer->setSingleShot(true);
+ connect(pollTimer, SIGNAL(timeout()), this, SLOT(pollBalanceChanged()));
+
subscribeToCoreSignals();
}
@@ -62,27 +72,47 @@ void WalletModel::updateStatus()
emit encryptionStatusChanged(newEncryptionStatus);
}
-void WalletModel::updateTransaction(const QString &hash, int status)
+void WalletModel::pollBalanceChanged()
{
- if(transactionTableModel)
- transactionTableModel->updateTransaction(hash, status);
+ if(nBestHeight != cachedNumBlocks) {
+ cachedNumBlocks = nBestHeight;
+ checkBalanceChanged();
+ }
- // Balance and number of transactions might have changed
+ if(cachedUnconfirmedBalance || cachedImmatureBalance)
+ pollTimer->start();
+}
+
+void WalletModel::checkBalanceChanged()
+{
qint64 newBalance = getBalance();
qint64 newUnconfirmedBalance = getUnconfirmedBalance();
qint64 newImmatureBalance = getImmatureBalance();
- int newNumTransactions = getNumTransactions();
- if(cachedBalance != newBalance || cachedUnconfirmedBalance != newUnconfirmedBalance || cachedImmatureBalance != newImmatureBalance)
+ if(cachedBalance != newBalance || cachedUnconfirmedBalance != newUnconfirmedBalance || cachedImmatureBalance != newImmatureBalance) {
+ cachedBalance = newBalance;
+ cachedUnconfirmedBalance = newUnconfirmedBalance;
+ cachedImmatureBalance = newImmatureBalance;
emit balanceChanged(newBalance, newUnconfirmedBalance, newImmatureBalance);
+ }
+}
- if(cachedNumTransactions != newNumTransactions)
- emit numTransactionsChanged(newNumTransactions);
+void WalletModel::updateTransaction(const QString &hash, int status)
+{
+ if(transactionTableModel)
+ transactionTableModel->updateTransaction(hash, status);
- cachedBalance = newBalance;
- cachedUnconfirmedBalance = newUnconfirmedBalance;
- cachedImmatureBalance = newImmatureBalance;
- cachedNumTransactions = newNumTransactions;
+ // Balance and number of transactions might have changed
+ checkBalanceChanged();
+
+ if(cachedUnconfirmedBalance || cachedImmatureBalance)
+ pollTimer->start();
+
+ int newNumTransactions = getNumTransactions();
+ if(cachedNumTransactions != newNumTransactions) {
+ emit numTransactionsChanged(newNumTransactions);
+ cachedNumTransactions = newNumTransactions;
+ }
}
void WalletModel::updateAddressBook(const QString &address, const QString &label, bool isMine, int status)