Skip to content
This repository
Browse code

add CWalletTx::GetImmatureCredit() and use it in CWallet::GetImmature…

…Balance()
  • Loading branch information...
commit 966a0e8cc94f2590521e0a2513e0cea32b5bb005 1 parent 0d5b1d2
P. Kaufmann authored June 18, 2012
5  src/wallet.cpp
@@ -926,9 +926,8 @@ int64 CWallet::GetImmatureBalance() const
926 926
         LOCK(cs_wallet);
927 927
         for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
928 928
         {
929  
-            const CWalletTx& pcoin = (*it).second;
930  
-            if (pcoin.IsCoinBase() && pcoin.GetBlocksToMaturity() > 0 && pcoin.IsInMainChain())
931  
-                nTotal += GetCredit(pcoin);
  929
+            const CWalletTx* pcoin = &(*it).second;
  930
+            nTotal += pcoin->GetImmatureCredit();
932 931
         }
933 932
     }
934 933
     return nTotal;
18  src/wallet.h
@@ -375,10 +375,12 @@ class CWalletTx : public CMerkleTx
375 375
     // memory only
376 376
     mutable bool fDebitCached;
377 377
     mutable bool fCreditCached;
  378
+    mutable bool fImmatureCreditCached;
378 379
     mutable bool fAvailableCreditCached;
379 380
     mutable bool fChangeCached;
380 381
     mutable int64 nDebitCached;
381 382
     mutable int64 nCreditCached;
  383
+    mutable int64 nImmatureCreditCached;
382 384
     mutable int64 nAvailableCreditCached;
383 385
     mutable int64 nChangeCached;
384 386
 
@@ -416,10 +418,12 @@ class CWalletTx : public CMerkleTx
416 418
         vfSpent.clear();
417 419
         fDebitCached = false;
418 420
         fCreditCached = false;
  421
+        fImmatureCreditCached = false;
419 422
         fAvailableCreditCached = false;
420 423
         fChangeCached = false;
421 424
         nDebitCached = 0;
422 425
         nCreditCached = 0;
  426
+        nImmatureCreditCached = 0;
423 427
         nAvailableCreditCached = 0;
424 428
         nChangeCached = 0;
425 429
         nOrderPos = -1;
@@ -563,6 +567,20 @@ class CWalletTx : public CMerkleTx
563 567
         return nCreditCached;
564 568
     }
565 569
 
  570
+    int64 GetImmatureCredit(bool fUseCache=true) const
  571
+    {
  572
+        if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain())
  573
+        {
  574
+            if (fUseCache && fImmatureCreditCached)
  575
+                return nImmatureCreditCached;
  576
+            nImmatureCreditCached = pwallet->GetCredit(*this);
  577
+            fImmatureCreditCached = true;
  578
+            return nImmatureCreditCached;
  579
+        }
  580
+
  581
+        return 0;
  582
+    }
  583
+
566 584
     int64 GetAvailableCredit(bool fUseCache=true) const
567 585
     {
568 586
         // Must wait until coinbase is safely deep enough in the chain before valuing it

0 notes on commit 966a0e8

Please sign in to comment.
Something went wrong with that request. Please try again.