@@ -1894,7 +1894,7 @@ CAmount CWalletTx::GetDebit(const isminefilter& filter) const
1894
1894
CAmount CWalletTx::GetCredit (const isminefilter& filter) const
1895
1895
{
1896
1896
// Must wait until coinbase is safely deep enough in the chain before valuing it
1897
- if (IsCoinBase () && GetBlocksToMaturity () > 0 )
1897
+ if (IsImmatureCoinBase () )
1898
1898
return 0 ;
1899
1899
1900
1900
CAmount credit = 0 ;
@@ -1926,8 +1926,7 @@ CAmount CWalletTx::GetCredit(const isminefilter& filter) const
1926
1926
1927
1927
CAmount CWalletTx::GetImmatureCredit (bool fUseCache ) const
1928
1928
{
1929
- if (IsCoinBase () && GetBlocksToMaturity () > 0 && IsInMainChain ())
1930
- {
1929
+ if (IsImmatureCoinBase () && IsInMainChain ()) {
1931
1930
if (fUseCache && fImmatureCreditCached )
1932
1931
return nImmatureCreditCached;
1933
1932
nImmatureCreditCached = pwallet->GetCredit (*tx, ISMINE_SPENDABLE);
@@ -1944,7 +1943,7 @@ CAmount CWalletTx::GetAvailableCredit(bool fUseCache, const isminefilter& filter
1944
1943
return 0 ;
1945
1944
1946
1945
// Must wait until coinbase is safely deep enough in the chain before valuing it
1947
- if (IsCoinBase () && GetBlocksToMaturity () > 0 )
1946
+ if (IsImmatureCoinBase () )
1948
1947
return 0 ;
1949
1948
1950
1949
CAmount* cache = nullptr ;
@@ -1985,8 +1984,7 @@ CAmount CWalletTx::GetAvailableCredit(bool fUseCache, const isminefilter& filter
1985
1984
1986
1985
CAmount CWalletTx::GetImmatureWatchOnlyCredit (const bool fUseCache ) const
1987
1986
{
1988
- if (IsCoinBase () && GetBlocksToMaturity () > 0 && IsInMainChain ())
1989
- {
1987
+ if (IsImmatureCoinBase () && IsInMainChain ()) {
1990
1988
if (fUseCache && fImmatureWatchCreditCached )
1991
1989
return nImmatureWatchCreditCached;
1992
1990
nImmatureWatchCreditCached = pwallet->GetCredit (*tx, ISMINE_WATCH_ONLY);
@@ -2199,7 +2197,7 @@ CAmount CWallet::GetLegacyBalance(const isminefilter& filter, int minDepth, cons
2199
2197
for (const auto & entry : mapWallet) {
2200
2198
const CWalletTx& wtx = entry.second ;
2201
2199
const int depth = wtx.GetDepthInMainChain ();
2202
- if (depth < 0 || !CheckFinalTx (*wtx.tx ) || wtx.GetBlocksToMaturity () > 0 ) {
2200
+ if (depth < 0 || !CheckFinalTx (*wtx.tx ) || wtx.IsImmatureCoinBase () ) {
2203
2201
continue ;
2204
2202
}
2205
2203
@@ -2259,7 +2257,7 @@ void CWallet::AvailableCoins(std::vector<COutput> &vCoins, bool fOnlySafe, const
2259
2257
if (!CheckFinalTx (*pcoin->tx ))
2260
2258
continue ;
2261
2259
2262
- if (pcoin->IsCoinBase () && pcoin-> GetBlocksToMaturity () > 0 )
2260
+ if (pcoin->IsImmatureCoinBase () )
2263
2261
continue ;
2264
2262
2265
2263
int nDepth = pcoin->GetDepthInMainChain ();
@@ -3528,7 +3526,7 @@ std::map<CTxDestination, CAmount> CWallet::GetAddressBalances()
3528
3526
if (!pcoin->IsTrusted ())
3529
3527
continue ;
3530
3528
3531
- if (pcoin->IsCoinBase () && pcoin-> GetBlocksToMaturity () > 0 )
3529
+ if (pcoin->IsImmatureCoinBase () )
3532
3530
continue ;
3533
3531
3534
3532
int nDepth = pcoin->GetDepthInMainChain ();
@@ -4406,6 +4404,11 @@ int CMerkleTx::GetBlocksToMaturity() const
4406
4404
return std::max (0 , (COINBASE_MATURITY+1 ) - chain_depth);
4407
4405
}
4408
4406
4407
+ bool CMerkleTx::IsImmatureCoinBase () const
4408
+ {
4409
+ // note GetBlocksToMaturity is 0 for non-coinbase tx
4410
+ return GetBlocksToMaturity () > 0 ;
4411
+ }
4409
4412
4410
4413
bool CWalletTx::AcceptToMemoryPool (const CAmount& nAbsurdFee, CValidationState& state)
4411
4414
{
0 commit comments