diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1690,7 +1690,7 @@ if (wtx.IsCoinBase()) { if (wtx.GetDepthInMainChain() < 1) { entry.push_back(Pair("category", "orphan")); - } else if (wtx.GetBlocksToMaturity() > 0) { + } else if (wtx.IsImmatureCoinBase()) { entry.push_back(Pair("category", "immature")); } else { entry.push_back(Pair("category", "generate")); @@ -1982,7 +1982,7 @@ std::list listReceived; std::list listSent; int nDepth = wtx.GetDepthInMainChain(); - if (wtx.GetBlocksToMaturity() > 0 || nDepth < 0) { + if (wtx.IsImmatureCoinBase() || nDepth < 0) { continue; } wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount, diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -252,6 +252,11 @@ const CBlockIndex *pindexRet; return GetDepthInMainChain(pindexRet) > 0; } + /** + * @return number of blocks to maturity for this transaction: + * 0 : is not a coinbase transaction, or is a mature coinbase transaction + * >0 : is a coinbase transaction which matures in this many blocks + */ int GetBlocksToMaturity() const; /** * Pass this transaction to the mempool. Fails if absolute fee exceeds @@ -266,6 +271,7 @@ TxId GetId() const { return tx->GetId(); } bool IsCoinBase() const { return tx->IsCoinBase(); } + bool IsImmatureCoinBase() const; }; /** diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1831,7 +1831,7 @@ Amount CWalletTx::GetCredit(const isminefilter &filter) const { // Must wait until coinbase is safely deep enough in the chain before // valuing it. - if (IsCoinBase() && GetBlocksToMaturity() > 0) { + if (IsImmatureCoinBase()) { return Amount::zero(); } @@ -1861,7 +1861,7 @@ } Amount CWalletTx::GetImmatureCredit(bool fUseCache) const { - if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain()) { + if (IsImmatureCoinBase() && IsInMainChain()) { if (fUseCache && fImmatureCreditCached) { return nImmatureCreditCached; } @@ -1881,7 +1881,7 @@ // Must wait until coinbase is safely deep enough in the chain before // valuing it. - if (IsCoinBase() && GetBlocksToMaturity() > 0) { + if (IsImmatureCoinBase()) { return Amount::zero(); } @@ -1907,7 +1907,7 @@ } Amount CWalletTx::GetImmatureWatchOnlyCredit(const bool &fUseCache) const { - if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain()) { + if (IsImmatureCoinBase() && IsInMainChain()) { if (fUseCache && fImmatureWatchCreditCached) { return nImmatureWatchCreditCached; } @@ -2191,8 +2191,8 @@ for (const auto &entry : mapWallet) { const CWalletTx &wtx = entry.second; const int depth = wtx.GetDepthInMainChain(); - if (depth < 0 || !CheckFinalTx(*wtx.tx) || - wtx.GetBlocksToMaturity() > 0) { + if (depth < 0 || !CheckFinalTx(*wtx.tx) || wtx.IsImmatureCoinBase()) { + continue; } @@ -2243,7 +2243,7 @@ continue; } - if (pcoin->IsCoinBase() && pcoin->GetBlocksToMaturity() > 0) { + if (pcoin->IsImmatureCoinBase()) { continue; } @@ -3523,7 +3523,7 @@ continue; } - if (pcoin->IsCoinBase() && pcoin->GetBlocksToMaturity() > 0) { + if (pcoin->IsImmatureCoinBase()) { continue; } @@ -4254,6 +4254,11 @@ return std::max(0, (COINBASE_MATURITY + 1) - GetDepthInMainChain()); } +bool CMerkleTx::IsImmatureCoinBase() const { + // note GetBlocksToMaturity is 0 for non-coinbase tx + return GetBlocksToMaturity() > 0; +} + bool CMerkleTx::AcceptToMemoryPool(const Amount nAbsurdFee, CValidationState &state) { return ::AcceptToMemoryPool(GetConfig(), mempool, state, tx, true, nullptr,