@@ -1894,7 +1894,7 @@ CAmount CWalletTx::GetDebit(const isminefilter& filter) const
18941894CAmount CWalletTx::GetCredit (const isminefilter& filter) const
18951895{
18961896 // Must wait until coinbase is safely deep enough in the chain before valuing it
1897- if (IsCoinBase () && GetBlocksToMaturity () > 0 )
1897+ if (IsImmatureCoinBase () )
18981898 return 0 ;
18991899
19001900 CAmount credit = 0 ;
@@ -1926,8 +1926,7 @@ CAmount CWalletTx::GetCredit(const isminefilter& filter) const
19261926
19271927CAmount CWalletTx::GetImmatureCredit (bool fUseCache ) const
19281928{
1929- if (IsCoinBase () && GetBlocksToMaturity () > 0 && IsInMainChain ())
1930- {
1929+ if (IsImmatureCoinBase () && IsInMainChain ()) {
19311930 if (fUseCache && fImmatureCreditCached )
19321931 return nImmatureCreditCached;
19331932 nImmatureCreditCached = pwallet->GetCredit (*tx, ISMINE_SPENDABLE);
@@ -1944,7 +1943,7 @@ CAmount CWalletTx::GetAvailableCredit(bool fUseCache, const isminefilter& filter
19441943 return 0 ;
19451944
19461945 // Must wait until coinbase is safely deep enough in the chain before valuing it
1947- if (IsCoinBase () && GetBlocksToMaturity () > 0 )
1946+ if (IsImmatureCoinBase () )
19481947 return 0 ;
19491948
19501949 CAmount* cache = nullptr ;
@@ -1985,8 +1984,7 @@ CAmount CWalletTx::GetAvailableCredit(bool fUseCache, const isminefilter& filter
19851984
19861985CAmount CWalletTx::GetImmatureWatchOnlyCredit (const bool fUseCache ) const
19871986{
1988- if (IsCoinBase () && GetBlocksToMaturity () > 0 && IsInMainChain ())
1989- {
1987+ if (IsImmatureCoinBase () && IsInMainChain ()) {
19901988 if (fUseCache && fImmatureWatchCreditCached )
19911989 return nImmatureWatchCreditCached;
19921990 nImmatureWatchCreditCached = pwallet->GetCredit (*tx, ISMINE_WATCH_ONLY);
@@ -2199,7 +2197,7 @@ CAmount CWallet::GetLegacyBalance(const isminefilter& filter, int minDepth, cons
21992197 for (const auto & entry : mapWallet) {
22002198 const CWalletTx& wtx = entry.second ;
22012199 const int depth = wtx.GetDepthInMainChain ();
2202- if (depth < 0 || !CheckFinalTx (*wtx.tx ) || wtx.GetBlocksToMaturity () > 0 ) {
2200+ if (depth < 0 || !CheckFinalTx (*wtx.tx ) || wtx.IsImmatureCoinBase () ) {
22032201 continue ;
22042202 }
22052203
@@ -2259,7 +2257,7 @@ void CWallet::AvailableCoins(std::vector<COutput> &vCoins, bool fOnlySafe, const
22592257 if (!CheckFinalTx (*pcoin->tx ))
22602258 continue ;
22612259
2262- if (pcoin->IsCoinBase () && pcoin-> GetBlocksToMaturity () > 0 )
2260+ if (pcoin->IsImmatureCoinBase () )
22632261 continue ;
22642262
22652263 int nDepth = pcoin->GetDepthInMainChain ();
@@ -3521,7 +3519,7 @@ std::map<CTxDestination, CAmount> CWallet::GetAddressBalances()
35213519 if (!pcoin->IsTrusted ())
35223520 continue ;
35233521
3524- if (pcoin->IsCoinBase () && pcoin-> GetBlocksToMaturity () > 0 )
3522+ if (pcoin->IsImmatureCoinBase () )
35253523 continue ;
35263524
35273525 int nDepth = pcoin->GetDepthInMainChain ();
@@ -4397,6 +4395,11 @@ int CMerkleTx::GetBlocksToMaturity() const
43974395 return std::max (0 , (COINBASE_MATURITY+1 ) - GetDepthInMainChain ());
43984396}
43994397
4398+ bool CMerkleTx::IsImmatureCoinBase () const
4399+ {
4400+ // note GetBlocksToMaturity is 0 for non-coinbase tx
4401+ return GetBlocksToMaturity () > 0 ;
4402+ }
44004403
44014404bool CWalletTx::AcceptToMemoryPool (const CAmount& nAbsurdFee, CValidationState& state)
44024405{
0 commit comments