Browse Source

Merge pull request #1479 from Diapolo/wallet_add_GetImmatureCredit

add CWalletTx::GetImmatureCredit() and use it in CWallet::GetImmatureBalance()
0.8
Wladimir J. van der Laan 12 years ago
parent
commit
f2b12807d0
  1. 5
      src/wallet.cpp
  2. 18
      src/wallet.h

5
src/wallet.cpp

@ -926,9 +926,8 @@ int64 CWallet::GetImmatureBalance() const @@ -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;

18
src/wallet.h

@ -375,10 +375,12 @@ public: @@ -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: @@ -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: @@ -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

Loading…
Cancel
Save