mirror of
https://github.com/kvazar-network/kevacoin.git
synced 2025-01-12 08:08:25 +00:00
Add a timer to check for changes in immature or unconfirmed balances,
when these are non-zero. Fixed a minor mem leak.
This commit is contained in:
parent
fe70b09c42
commit
6c83a8419b
@ -18,7 +18,7 @@ ClientModel::ClientModel(OptionsModel *optionsModel, QObject *parent) :
|
|||||||
{
|
{
|
||||||
numBlocksAtStartup = -1;
|
numBlocksAtStartup = -1;
|
||||||
|
|
||||||
pollTimer = new QTimer();
|
pollTimer = new QTimer(this);
|
||||||
pollTimer->setInterval(MODEL_UPDATE_DELAY);
|
pollTimer->setInterval(MODEL_UPDATE_DELAY);
|
||||||
pollTimer->start();
|
pollTimer->start();
|
||||||
connect(pollTimer, SIGNAL(timeout()), this, SLOT(updateTimer()));
|
connect(pollTimer, SIGNAL(timeout()), this, SLOT(updateTimer()));
|
||||||
|
@ -10,17 +10,27 @@
|
|||||||
#include "base58.h"
|
#include "base58.h"
|
||||||
|
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
WalletModel::WalletModel(CWallet *wallet, OptionsModel *optionsModel, QObject *parent) :
|
WalletModel::WalletModel(CWallet *wallet, OptionsModel *optionsModel, QObject *parent) :
|
||||||
QObject(parent), wallet(wallet), optionsModel(optionsModel), addressTableModel(0),
|
QObject(parent), wallet(wallet), optionsModel(optionsModel), addressTableModel(0),
|
||||||
transactionTableModel(0),
|
transactionTableModel(0),
|
||||||
cachedBalance(0), cachedUnconfirmedBalance(0), cachedImmatureBalance(0),
|
cachedBalance(0), cachedUnconfirmedBalance(0), cachedImmatureBalance(0),
|
||||||
cachedNumTransactions(0),
|
cachedNumTransactions(0),
|
||||||
cachedEncryptionStatus(Unencrypted)
|
cachedEncryptionStatus(Unencrypted),
|
||||||
|
cachedNumBlocks(0)
|
||||||
{
|
{
|
||||||
addressTableModel = new AddressTableModel(wallet, this);
|
addressTableModel = new AddressTableModel(wallet, this);
|
||||||
transactionTableModel = new TransactionTableModel(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();
|
subscribeToCoreSignals();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,27 +72,47 @@ void WalletModel::updateStatus()
|
|||||||
emit encryptionStatusChanged(newEncryptionStatus);
|
emit encryptionStatusChanged(newEncryptionStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WalletModel::pollBalanceChanged()
|
||||||
|
{
|
||||||
|
if(nBestHeight != cachedNumBlocks) {
|
||||||
|
cachedNumBlocks = nBestHeight;
|
||||||
|
checkBalanceChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(cachedUnconfirmedBalance || cachedImmatureBalance)
|
||||||
|
pollTimer->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WalletModel::checkBalanceChanged()
|
||||||
|
{
|
||||||
|
qint64 newBalance = getBalance();
|
||||||
|
qint64 newUnconfirmedBalance = getUnconfirmedBalance();
|
||||||
|
qint64 newImmatureBalance = getImmatureBalance();
|
||||||
|
|
||||||
|
if(cachedBalance != newBalance || cachedUnconfirmedBalance != newUnconfirmedBalance || cachedImmatureBalance != newImmatureBalance) {
|
||||||
|
cachedBalance = newBalance;
|
||||||
|
cachedUnconfirmedBalance = newUnconfirmedBalance;
|
||||||
|
cachedImmatureBalance = newImmatureBalance;
|
||||||
|
emit balanceChanged(newBalance, newUnconfirmedBalance, newImmatureBalance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void WalletModel::updateTransaction(const QString &hash, int status)
|
void WalletModel::updateTransaction(const QString &hash, int status)
|
||||||
{
|
{
|
||||||
if(transactionTableModel)
|
if(transactionTableModel)
|
||||||
transactionTableModel->updateTransaction(hash, status);
|
transactionTableModel->updateTransaction(hash, status);
|
||||||
|
|
||||||
// Balance and number of transactions might have changed
|
// Balance and number of transactions might have changed
|
||||||
qint64 newBalance = getBalance();
|
checkBalanceChanged();
|
||||||
qint64 newUnconfirmedBalance = getUnconfirmedBalance();
|
|
||||||
qint64 newImmatureBalance = getImmatureBalance();
|
if(cachedUnconfirmedBalance || cachedImmatureBalance)
|
||||||
|
pollTimer->start();
|
||||||
|
|
||||||
int newNumTransactions = getNumTransactions();
|
int newNumTransactions = getNumTransactions();
|
||||||
|
if(cachedNumTransactions != newNumTransactions) {
|
||||||
if(cachedBalance != newBalance || cachedUnconfirmedBalance != newUnconfirmedBalance || cachedImmatureBalance != newImmatureBalance)
|
|
||||||
emit balanceChanged(newBalance, newUnconfirmedBalance, newImmatureBalance);
|
|
||||||
|
|
||||||
if(cachedNumTransactions != newNumTransactions)
|
|
||||||
emit numTransactionsChanged(newNumTransactions);
|
emit numTransactionsChanged(newNumTransactions);
|
||||||
|
cachedNumTransactions = newNumTransactions;
|
||||||
cachedBalance = newBalance;
|
}
|
||||||
cachedUnconfirmedBalance = newUnconfirmedBalance;
|
|
||||||
cachedImmatureBalance = newImmatureBalance;
|
|
||||||
cachedNumTransactions = newNumTransactions;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WalletModel::updateAddressBook(const QString &address, const QString &label, bool isMine, int status)
|
void WalletModel::updateAddressBook(const QString &address, const QString &label, bool isMine, int status)
|
||||||
|
@ -10,6 +10,10 @@ class AddressTableModel;
|
|||||||
class TransactionTableModel;
|
class TransactionTableModel;
|
||||||
class CWallet;
|
class CWallet;
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
class QTimer;
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
class SendCoinsRecipient
|
class SendCoinsRecipient
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -120,9 +124,14 @@ private:
|
|||||||
qint64 cachedImmatureBalance;
|
qint64 cachedImmatureBalance;
|
||||||
qint64 cachedNumTransactions;
|
qint64 cachedNumTransactions;
|
||||||
EncryptionStatus cachedEncryptionStatus;
|
EncryptionStatus cachedEncryptionStatus;
|
||||||
|
int cachedNumBlocks;
|
||||||
|
|
||||||
|
QTimer *pollTimer;
|
||||||
|
|
||||||
void subscribeToCoreSignals();
|
void subscribeToCoreSignals();
|
||||||
void unsubscribeFromCoreSignals();
|
void unsubscribeFromCoreSignals();
|
||||||
|
void checkBalanceChanged();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
// Signal that balance in wallet changed
|
// Signal that balance in wallet changed
|
||||||
void balanceChanged(qint64 balance, qint64 unconfirmedBalance, qint64 immatureBalance);
|
void balanceChanged(qint64 balance, qint64 unconfirmedBalance, qint64 immatureBalance);
|
||||||
@ -148,6 +157,8 @@ public slots:
|
|||||||
void updateTransaction(const QString &hash, int status);
|
void updateTransaction(const QString &hash, int status);
|
||||||
/* New, updated or removed address book entry */
|
/* New, updated or removed address book entry */
|
||||||
void updateAddressBook(const QString &address, const QString &label, bool isMine, int status);
|
void updateAddressBook(const QString &address, const QString &label, bool isMine, int status);
|
||||||
|
/* Current, immature or unconfirmed balance might have changed - emit 'balanceChanged' if so */
|
||||||
|
void pollBalanceChanged();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user