Mercurial > hg > bitcoin
changeset 2714:33d5155f1da3 draft
Merge pull request #837 from sje397/ShowImmatureBalance
Added 'immature balance' for miners. Only displayed if the balance is > 0
author | Wladimir J. van der Laan <laanwj@gmail.com> |
---|---|
date | Sat, 02 Jun 2012 02:35:48 -0700 |
parents | 17ecc63fa1f5 (current diff) a9a09da51502 (diff) |
children | f3b48519c6ba ac431543ca42 7d48dd4a812b |
files | src/qt/walletmodel.cpp src/wallet.cpp src/wallet.h |
diffstat | 9 files changed, 87 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/src/qt/forms/overviewpage.ui +++ b/src/qt/forms/overviewpage.ui @@ -6,7 +6,7 @@ <rect> <x>0</x> <y>0</y> - <width>552</width> + <width>573</width> <height>342</height> </rect> </property> @@ -141,14 +141,14 @@ </property> </widget> </item> - <item row="2" column="0"> + <item row="3" column="0"> <widget class="QLabel" name="label_2"> <property name="text"> <string>Number of transactions:</string> </property> </widget> </item> - <item row="2" column="1"> + <item row="3" column="1"> <widget class="QLabel" name="labelNumTransactions"> <property name="toolTip"> <string>Total number of transactions in wallet</string> @@ -158,6 +158,32 @@ </property> </widget> </item> + <item row="2" column="0"> + <widget class="QLabel" name="labelImmatureText"> + <property name="text"> + <string>Immature:</string> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QLabel" name="labelImmature"> + <property name="font"> + <font> + <weight>75</weight> + <bold>true</bold> + </font> + </property> + <property name="toolTip"> + <string>Mined balance that has not yet matured</string> + </property> + <property name="text"> + <string notr="true">0 BTC</string> + </property> + <property name="textInteractionFlags"> + <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set> + </property> + </widget> + </item> </layout> </item> </layout>
--- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -94,7 +94,9 @@ ui(new Ui::OverviewPage), currentBalance(-1), currentUnconfirmedBalance(-1), - txdelegate(new TxViewDelegate()), filter(0) + currentImmatureBalance(-1), + txdelegate(new TxViewDelegate()), + filter(0) { ui->setupUi(this); @@ -125,13 +127,21 @@ delete ui; } -void OverviewPage::setBalance(qint64 balance, qint64 unconfirmedBalance) +void OverviewPage::setBalance(qint64 balance, qint64 unconfirmedBalance, qint64 immatureBalance) { int unit = model->getOptionsModel()->getDisplayUnit(); currentBalance = balance; currentUnconfirmedBalance = unconfirmedBalance; + currentImmatureBalance = immatureBalance; ui->labelBalance->setText(BitcoinUnits::formatWithUnit(unit, balance)); ui->labelUnconfirmed->setText(BitcoinUnits::formatWithUnit(unit, unconfirmedBalance)); + ui->labelImmature->setText(BitcoinUnits::formatWithUnit(unit, immatureBalance)); + + // only show immature (newly mined) balance if it's non-zero, so as not to complicate things + // for the non-mining users + bool showImmature = immatureBalance != 0; + ui->labelImmature->setVisible(showImmature); + ui->labelImmatureText->setVisible(showImmature); } void OverviewPage::setNumTransactions(int count) @@ -156,8 +166,8 @@ ui->listTransactions->setModelColumn(TransactionTableModel::ToAddress); // Keep up to date with wallet - setBalance(model->getBalance(), model->getUnconfirmedBalance()); - connect(model, SIGNAL(balanceChanged(qint64, qint64)), this, SLOT(setBalance(qint64, qint64))); + setBalance(model->getBalance(), model->getUnconfirmedBalance(), model->getImmatureBalance()); + connect(model, SIGNAL(balanceChanged(qint64, qint64, qint64)), this, SLOT(setBalance(qint64, qint64, qint64))); setNumTransactions(model->getNumTransactions()); connect(model, SIGNAL(numTransactionsChanged(int)), this, SLOT(setNumTransactions(int))); @@ -171,7 +181,7 @@ if(!model || !model->getOptionsModel()) return; if(currentBalance != -1) - setBalance(currentBalance, currentUnconfirmedBalance); + setBalance(currentBalance, currentUnconfirmedBalance, currentImmatureBalance); txdelegate->unit = model->getOptionsModel()->getDisplayUnit(); ui->listTransactions->update();
--- a/src/qt/overviewpage.h +++ b/src/qt/overviewpage.h @@ -27,7 +27,7 @@ void showOutOfSyncWarning(bool fShow); public slots: - void setBalance(qint64 balance, qint64 unconfirmedBalance); + void setBalance(qint64 balance, qint64 unconfirmedBalance, qint64 immatureBalance); void setNumTransactions(int count); signals: @@ -38,6 +38,7 @@ WalletModel *model; qint64 currentBalance; qint64 currentUnconfirmedBalance; + qint64 currentImmatureBalance; TxViewDelegate *txdelegate; TransactionFilterProxy *filter;
--- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -48,8 +48,8 @@ } if(model) { - setBalance(model->getBalance(), model->getUnconfirmedBalance()); - connect(model, SIGNAL(balanceChanged(qint64, qint64)), this, SLOT(setBalance(qint64, qint64))); + setBalance(model->getBalance(), model->getUnconfirmedBalance(), model->getImmatureBalance()); + connect(model, SIGNAL(balanceChanged(qint64, qint64, qint64)), this, SLOT(setBalance(qint64, qint64, qint64))); } } @@ -277,9 +277,10 @@ pasteEntry(rv); } -void SendCoinsDialog::setBalance(qint64 balance, qint64 unconfirmedBalance) +void SendCoinsDialog::setBalance(qint64 balance, qint64 unconfirmedBalance, qint64 immatureBalance) { Q_UNUSED(unconfirmedBalance); + Q_UNUSED(immatureBalance); if(!model || !model->getOptionsModel()) return;
--- a/src/qt/sendcoinsdialog.h +++ b/src/qt/sendcoinsdialog.h @@ -38,7 +38,7 @@ void accept(); SendCoinsEntry *addEntry(); void updateRemoveEnabled(); - void setBalance(qint64 balance, qint64 unconfirmedBalance); + void setBalance(qint64 balance, qint64 unconfirmedBalance, qint64 immatureBalance); private: Ui::SendCoinsDialog *ui;
--- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -14,7 +14,8 @@ WalletModel::WalletModel(CWallet *wallet, OptionsModel *optionsModel, QObject *parent) : QObject(parent), wallet(wallet), optionsModel(optionsModel), addressTableModel(0), transactionTableModel(0), - cachedBalance(0), cachedUnconfirmedBalance(0), cachedNumTransactions(0), + cachedBalance(0), cachedUnconfirmedBalance(0), cachedImmatureBalance(0), + cachedNumTransactions(0), cachedEncryptionStatus(Unencrypted) { addressTableModel = new AddressTableModel(wallet, this); @@ -38,6 +39,11 @@ return wallet->GetUnconfirmedBalance(); } +qint64 WalletModel::getImmatureBalance() const +{ + return wallet->GetImmatureBalance(); +} + int WalletModel::getNumTransactions() const { int numTransactions = 0; @@ -64,15 +70,18 @@ // Balance and number of transactions might have changed qint64 newBalance = getBalance(); qint64 newUnconfirmedBalance = getUnconfirmedBalance(); + qint64 newImmatureBalance = getImmatureBalance(); int newNumTransactions = getNumTransactions(); - if(cachedBalance != newBalance || cachedUnconfirmedBalance != newUnconfirmedBalance) - emit balanceChanged(newBalance, newUnconfirmedBalance); + if(cachedBalance != newBalance || cachedUnconfirmedBalance != newUnconfirmedBalance || cachedImmatureBalance != newImmatureBalance) + emit balanceChanged(newBalance, newUnconfirmedBalance, newImmatureBalance); + if(cachedNumTransactions != newNumTransactions) emit numTransactionsChanged(newNumTransactions); cachedBalance = newBalance; cachedUnconfirmedBalance = newUnconfirmedBalance; + cachedImmatureBalance = newImmatureBalance; cachedNumTransactions = newNumTransactions; }
--- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -52,6 +52,7 @@ qint64 getBalance() const; qint64 getUnconfirmedBalance() const; + qint64 getImmatureBalance() const; int getNumTransactions() const; EncryptionStatus getEncryptionStatus() const; @@ -116,6 +117,7 @@ // Cache some values to be able to detect changes qint64 cachedBalance; qint64 cachedUnconfirmedBalance; + qint64 cachedImmatureBalance; qint64 cachedNumTransactions; EncryptionStatus cachedEncryptionStatus; @@ -123,7 +125,7 @@ void unsubscribeFromCoreSignals(); signals: // Signal that balance in wallet changed - void balanceChanged(qint64 balance, qint64 unconfirmedBalance); + void balanceChanged(qint64 balance, qint64 unconfirmedBalance, qint64 immatureBalance); // Number of transactions in wallet changed void numTransactionsChanged(int count);
--- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -567,7 +567,7 @@ } -void CWalletTx::GetAccountAmounts(const string& strAccount, int64& nGenerated, int64& nReceived, +void CWalletTx::GetAccountAmounts(const string& strAccount, int64& nGenerated, int64& nReceived, int64& nSent, int64& nFee) const { nGenerated = nReceived = nSent = nFee = 0; @@ -851,9 +851,8 @@ for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) { const CWalletTx* pcoin = &(*it).second; - if (!pcoin->IsFinal() || !pcoin->IsConfirmed()) - continue; - nTotal += pcoin->GetAvailableCredit(); + if (pcoin->IsFinal() && pcoin->IsConfirmed()) + nTotal += pcoin->GetAvailableCredit(); } } @@ -868,9 +867,23 @@ for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) { const CWalletTx* pcoin = &(*it).second; - if (pcoin->IsFinal() && pcoin->IsConfirmed()) - continue; - nTotal += pcoin->GetAvailableCredit(); + if (!pcoin->IsFinal() || !pcoin->IsConfirmed()) + nTotal += pcoin->GetAvailableCredit(); + } + } + return nTotal; +} + +int64 CWallet::GetImmatureBalance() const +{ + int64 nTotal = 0; + { + LOCK(cs_wallet); + for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) + { + const CWalletTx& pcoin = (*it).second; + if (pcoin.IsCoinBase() && pcoin.GetBlocksToMaturity() > 0 && pcoin.GetDepthInMainChain() >= 2) + nTotal += GetCredit(pcoin); } } return nTotal;
--- a/src/wallet.h +++ b/src/wallet.h @@ -144,6 +144,7 @@ void ResendWalletTransactions(); int64 GetBalance() const; int64 GetUnconfirmedBalance() const; + int64 GetImmatureBalance() const; bool CreateTransaction(const std::vector<std::pair<CScript, int64> >& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet); bool CreateTransaction(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew, CReserveKey& reservekey, int64& nFeeRet); bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey);