aboutsummaryrefslogtreecommitdiff
path: root/src/qt/walletmodel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/qt/walletmodel.cpp')
-rw-r--r--src/qt/walletmodel.cpp93
1 files changed, 52 insertions, 41 deletions
diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp
index 7317c32766..8d2c2e96d8 100644
--- a/src/qt/walletmodel.cpp
+++ b/src/qt/walletmodel.cpp
@@ -31,10 +31,13 @@ WalletModel::WalletModel(CWallet *wallet, OptionsModel *optionsModel, QObject *p
transactionTableModel(0),
recentRequestsTableModel(0),
cachedBalance(0), cachedUnconfirmedBalance(0), cachedImmatureBalance(0),
- cachedNumTransactions(0),
cachedEncryptionStatus(Unencrypted),
cachedNumBlocks(0)
{
+ fProcessingQueuedTransactions = false;
+ fHaveWatchOnly = wallet->HaveWatchOnly();
+ fForceCheckBalanceChanged = false;
+
addressTableModel = new AddressTableModel(wallet, this);
transactionTableModel = new TransactionTableModel(wallet, this);
recentRequestsTableModel = new RecentRequestsTableModel(wallet, this);
@@ -79,6 +82,11 @@ qint64 WalletModel::getImmatureBalance() const
return wallet->GetImmatureBalance();
}
+bool WalletModel::haveWatchOnly() const
+{
+ return fHaveWatchOnly;
+}
+
qint64 WalletModel::getWatchBalance() const
{
return wallet->GetWatchOnlyBalance();
@@ -94,18 +102,6 @@ qint64 WalletModel::getWatchImmatureBalance() const
return wallet->GetImmatureWatchOnlyBalance();
}
-int WalletModel::getNumTransactions() const
-{
- int numTransactions = 0;
- {
- LOCK(wallet->cs_wallet);
- // the size of mapWallet contains the number of unique transaction IDs
- // (e.g. payments to yourself generate 2 transactions, but both share the same transaction ID)
- numTransactions = wallet->mapWallet.size();
- }
- return numTransactions;
-}
-
void WalletModel::updateStatus()
{
EncryptionStatus newEncryptionStatus = getEncryptionStatus();
@@ -126,8 +122,10 @@ void WalletModel::pollBalanceChanged()
if(!lockWallet)
return;
- if(chainActive.Height() != cachedNumBlocks)
+ if(fForceCheckBalanceChanged || chainActive.Height() != cachedNumBlocks)
{
+ fForceCheckBalanceChanged = false;
+
// Balance and number of transactions might have changed
cachedNumBlocks = chainActive.Height();
@@ -142,9 +140,15 @@ void WalletModel::checkBalanceChanged()
qint64 newBalance = getBalance();
qint64 newUnconfirmedBalance = getUnconfirmedBalance();
qint64 newImmatureBalance = getImmatureBalance();
- qint64 newWatchOnlyBalance = getWatchBalance();
- qint64 newWatchUnconfBalance = getWatchUnconfirmedBalance();
- qint64 newWatchImmatureBalance = getWatchImmatureBalance();
+ qint64 newWatchOnlyBalance = 0;
+ qint64 newWatchUnconfBalance = 0;
+ qint64 newWatchImmatureBalance = 0;
+ if (haveWatchOnly())
+ {
+ newWatchOnlyBalance = getWatchBalance();
+ newWatchUnconfBalance = getWatchUnconfirmedBalance();
+ newWatchImmatureBalance = getWatchImmatureBalance();
+ }
if(cachedBalance != newBalance || cachedUnconfirmedBalance != newUnconfirmedBalance || cachedImmatureBalance != newImmatureBalance ||
cachedWatchOnlyBalance != newWatchOnlyBalance || cachedWatchUnconfBalance != newWatchUnconfBalance || cachedWatchImmatureBalance != newWatchImmatureBalance)
@@ -162,26 +166,11 @@ void WalletModel::checkBalanceChanged()
void WalletModel::updateTransaction(const QString &hash, int status)
{
- if (status == CT_GOT_CONFLICT)
- {
- emit message(tr("Conflict Received"),
- tr("WARNING: Transaction may never be confirmed. Its input was seen being spent by another transaction on the network. Wait for confirmation!"),
- CClientUIInterface::MSG_WARNING);
- return;
- }
-
if(transactionTableModel)
transactionTableModel->updateTransaction(hash, status);
// Balance and number of transactions might have changed
- checkBalanceChanged();
-
- int newNumTransactions = getNumTransactions();
- if(cachedNumTransactions != newNumTransactions)
- {
- cachedNumTransactions = newNumTransactions;
- emit numTransactionsChanged(newNumTransactions);
- }
+ fForceCheckBalanceChanged = true;
}
void WalletModel::updateAddressBook(const QString &address, const QString &label,
@@ -191,6 +180,12 @@ void WalletModel::updateAddressBook(const QString &address, const QString &label
addressTableModel->updateEntry(address, label, isMine, purpose, status);
}
+void WalletModel::updateWatchOnlyFlag(bool fHaveWatchonly)
+{
+ fHaveWatchOnly = fHaveWatchonly;
+ emit notifyWatchonlyChanged(fHaveWatchonly);
+}
+
bool WalletModel::validateAddress(const QString &address)
{
CBitcoinAddress addressParsed(address.toStdString());
@@ -352,6 +347,7 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(WalletModelTransaction &tran
}
emit coinsSent(wallet, rcp, transaction_array);
}
+ checkBalanceChanged(); // update balance immediately, otherwise there could be a short noticeable delay until pollBalanceChanged hits
return SendCoinsReturn(OK);
}
@@ -481,21 +477,34 @@ static void NotifyTransactionChanged(WalletModel *walletmodel, CWallet *wallet,
static void ShowProgress(WalletModel *walletmodel, const std::string &title, int nProgress)
{
- // emits signal "showProgress"
- QMetaObject::invokeMethod(walletmodel, "showProgress", Qt::QueuedConnection,
- Q_ARG(QString, QString::fromStdString(title)),
- Q_ARG(int, nProgress));
-
if (nProgress == 0)
fQueueNotifications = true;
if (nProgress == 100)
{
fQueueNotifications = false;
- BOOST_FOREACH(const PAIRTYPE(uint256, ChangeType)& notification, vQueueNotifications)
- NotifyTransactionChanged(walletmodel, NULL, notification.first, notification.second);
+ if (vQueueNotifications.size() > 10) // prevent balloon spam, show maximum 10 balloons
+ QMetaObject::invokeMethod(walletmodel, "setProcessingQueuedTransactions", Qt::QueuedConnection, Q_ARG(bool, true));
+ for (unsigned int i = 0; i < vQueueNotifications.size(); ++i)
+ {
+ if (vQueueNotifications.size() - i <= 10)
+ QMetaObject::invokeMethod(walletmodel, "setProcessingQueuedTransactions", Qt::QueuedConnection, Q_ARG(bool, false));
+
+ NotifyTransactionChanged(walletmodel, NULL, vQueueNotifications[i].first, vQueueNotifications[i].second);
+ }
std::vector<std::pair<uint256, ChangeType> >().swap(vQueueNotifications); // clear
}
+
+ // emits signal "showProgress"
+ QMetaObject::invokeMethod(walletmodel, "showProgress", Qt::QueuedConnection,
+ Q_ARG(QString, QString::fromStdString(title)),
+ Q_ARG(int, nProgress));
+}
+
+static void NotifyWatchonlyChanged(WalletModel *walletmodel, bool fHaveWatchonly)
+{
+ QMetaObject::invokeMethod(walletmodel, "updateWatchOnlyFlag", Qt::QueuedConnection,
+ Q_ARG(bool, fHaveWatchonly));
}
void WalletModel::subscribeToCoreSignals()
@@ -505,6 +514,7 @@ void WalletModel::subscribeToCoreSignals()
wallet->NotifyAddressBookChanged.connect(boost::bind(NotifyAddressBookChanged, this, _1, _2, _3, _4, _5, _6));
wallet->NotifyTransactionChanged.connect(boost::bind(NotifyTransactionChanged, this, _1, _2, _3));
wallet->ShowProgress.connect(boost::bind(ShowProgress, this, _1, _2));
+ wallet->NotifyWatchonlyChanged.connect(boost::bind(NotifyWatchonlyChanged, this, _1));
}
void WalletModel::unsubscribeFromCoreSignals()
@@ -514,6 +524,7 @@ void WalletModel::unsubscribeFromCoreSignals()
wallet->NotifyAddressBookChanged.disconnect(boost::bind(NotifyAddressBookChanged, this, _1, _2, _3, _4, _5, _6));
wallet->NotifyTransactionChanged.disconnect(boost::bind(NotifyTransactionChanged, this, _1, _2, _3));
wallet->ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2));
+ wallet->NotifyWatchonlyChanged.disconnect(boost::bind(NotifyWatchonlyChanged, this, _1));
}
// WalletModel::UnlockContext implementation
@@ -611,7 +622,7 @@ void WalletModel::listCoins(std::map<QString, std::vector<COutput> >& mapCoins)
CTxDestination address;
if(!out.fSpendable || !ExtractDestination(cout.tx->vout[cout.i].scriptPubKey, address))
continue;
- mapCoins[CBitcoinAddress(address).ToString().c_str()].push_back(out);
+ mapCoins[QString::fromStdString(CBitcoinAddress(address).ToString())].push_back(out);
}
}