@@ -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 ();
@@ -3521,7 +3519,7 @@ std::map<CTxDestination, CAmount> CWallet::GetAddressBalances()
3521
3519
if (!pcoin->IsTrusted ())
3522
3520
continue ;
3523
3521
3524
- if (pcoin->IsCoinBase () && pcoin-> GetBlocksToMaturity () > 0 )
3522
+ if (pcoin->IsImmatureCoinBase () )
3525
3523
continue ;
3526
3524
3527
3525
int nDepth = pcoin->GetDepthInMainChain ();
@@ -4397,6 +4395,11 @@ int CMerkleTx::GetBlocksToMaturity() const
4397
4395
return std::max (0 , (COINBASE_MATURITY+1 ) - GetDepthInMainChain ());
4398
4396
}
4399
4397
4398
+ bool CMerkleTx::IsImmatureCoinBase () const
4399
+ {
4400
+ // note GetBlocksToMaturity is 0 for non-coinbase tx
4401
+ return GetBlocksToMaturity () > 0 ;
4402
+ }
4400
4403
4401
4404
bool CWalletTx::AcceptToMemoryPool (const CAmount& nAbsurdFee, CValidationState& state)
4402
4405
{
0 commit comments