aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPhilip Kaufmann <phil.kaufmann@t-online.de>2012-06-18 08:32:33 +0200
committerPhilip Kaufmann <phil.kaufmann@t-online.de>2012-11-13 07:56:48 +0100
commit966a0e8cc94f2590521e0a2513e0cea32b5bb005 (patch)
treea6fb31a0f82a7edc186bd46f1478f3d75930368f /src
parent0d5b1d2a3e0c154da2228632524a077b2b65aa2a (diff)
downloadbitcoin-966a0e8cc94f2590521e0a2513e0cea32b5bb005.tar.xz
add CWalletTx::GetImmatureCredit() and use it in CWallet::GetImmatureBalance()
Diffstat (limited to 'src')
-rw-r--r--src/wallet.cpp5
-rw-r--r--src/wallet.h18
2 files changed, 20 insertions, 3 deletions
diff --git a/src/wallet.cpp b/src/wallet.cpp
index ae9f695e9f..0115e56b8e 100644
--- a/src/wallet.cpp
+++ b/src/wallet.cpp
@@ -926,9 +926,8 @@ int64 CWallet::GetImmatureBalance() const
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.IsInMainChain())
- nTotal += GetCredit(pcoin);
+ const CWalletTx* pcoin = &(*it).second;
+ nTotal += pcoin->GetImmatureCredit();
}
}
return nTotal;
diff --git a/src/wallet.h b/src/wallet.h
index 43b695c597..5e2f8e0ba1 100644
--- a/src/wallet.h
+++ b/src/wallet.h
@@ -375,10 +375,12 @@ public:
// memory only
mutable bool fDebitCached;
mutable bool fCreditCached;
+ mutable bool fImmatureCreditCached;
mutable bool fAvailableCreditCached;
mutable bool fChangeCached;
mutable int64 nDebitCached;
mutable int64 nCreditCached;
+ mutable int64 nImmatureCreditCached;
mutable int64 nAvailableCreditCached;
mutable int64 nChangeCached;
@@ -416,10 +418,12 @@ public:
vfSpent.clear();
fDebitCached = false;
fCreditCached = false;
+ fImmatureCreditCached = false;
fAvailableCreditCached = false;
fChangeCached = false;
nDebitCached = 0;
nCreditCached = 0;
+ nImmatureCreditCached = 0;
nAvailableCreditCached = 0;
nChangeCached = 0;
nOrderPos = -1;
@@ -563,6 +567,20 @@ public:
return nCreditCached;
}
+ int64 GetImmatureCredit(bool fUseCache=true) const
+ {
+ if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain())
+ {
+ if (fUseCache && fImmatureCreditCached)
+ return nImmatureCreditCached;
+ nImmatureCreditCached = pwallet->GetCredit(*this);
+ fImmatureCreditCached = true;
+ return nImmatureCreditCached;
+ }
+
+ return 0;
+ }
+
int64 GetAvailableCredit(bool fUseCache=true) const
{
// Must wait until coinbase is safely deep enough in the chain before valuing it