Skip to content

Commit

Permalink
Merge pull request bitcoin#1479 from Diapolo/wallet_add_GetImmatureCr…
Browse files Browse the repository at this point in the history
…edit

add CWalletTx::GetImmatureCredit() and use it in CWallet::GetImmatureBalance()
  • Loading branch information
laanwj committed Nov 13, 2012
2 parents 0d5b1d2 + 966a0e8 commit f2b1280
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 18 additions & 0 deletions src/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,12 @@ class CWalletTx : public CMerkleTx
// 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;

Expand Down Expand Up @@ -416,10 +418,12 @@ class CWalletTx : public CMerkleTx
vfSpent.clear();
fDebitCached = false;
fCreditCached = false;
fImmatureCreditCached = false;
fAvailableCreditCached = false;
fChangeCached = false;
nDebitCached = 0;
nCreditCached = 0;
nImmatureCreditCached = 0;
nAvailableCreditCached = 0;
nChangeCached = 0;
nOrderPos = -1;
Expand Down Expand Up @@ -563,6 +567,20 @@ class CWalletTx : public CMerkleTx
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
Expand Down

0 comments on commit f2b1280

Please sign in to comment.