aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/wallet.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2018-08-25 16:52:25 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2018-08-25 16:53:21 +0200
commit776fa60c4bebb809dfadd9859cc2789769d492b9 (patch)
tree661ea64b1d10ca8b09d3b5d1253467df807c1a84 /src/wallet/wallet.cpp
parent55c18a45305f9e89a726f8cf82a7b16a2ab7f955 (diff)
parent23f434378153cf764230066662f3ec3ad614ff30 (diff)
downloadbitcoin-776fa60c4bebb809dfadd9859cc2789769d492b9.tar.xz
Merge #13631: Add CMerkleTx::IsImmatureCoinBase method
23f434378153cf764230066662f3ec3ad614ff30 Add CMerkleTx::IsImmatureCoinBase method (Ben Woosley) Pull request description: All but one call to `GetBlocksToMaturity` is testing it relative to 0 for the purposes of determining whether the coinbase tx is immature. In such case, the value greater than 0 implies that the tx is coinbase, so there is no need to separately test that status. This names the concept for easy singular use. Tree-SHA512: 4470d07404a0707144f9827b9a94c5c4905f23ee6f9248edc5df599a59d28e21ea0201d8abe5d5d73b39cb05b60c861ea8e04767eef04433e2ee95dcfed653ee
Diffstat (limited to 'src/wallet/wallet.cpp')
-rw-r--r--src/wallet/wallet.cpp21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index 5a7fdf9a85..d0857bcb72 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -1894,7 +1894,7 @@ CAmount CWalletTx::GetDebit(const isminefilter& filter) const
CAmount 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 0;
CAmount credit = 0;
@@ -1926,8 +1926,7 @@ CAmount CWalletTx::GetCredit(const isminefilter& filter) const
CAmount CWalletTx::GetImmatureCredit(bool fUseCache) const
{
- if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain())
- {
+ if (IsImmatureCoinBase() && IsInMainChain()) {
if (fUseCache && fImmatureCreditCached)
return nImmatureCreditCached;
nImmatureCreditCached = pwallet->GetCredit(*tx, ISMINE_SPENDABLE);
@@ -1944,7 +1943,7 @@ CAmount CWalletTx::GetAvailableCredit(bool fUseCache, const isminefilter& filter
return 0;
// Must wait until coinbase is safely deep enough in the chain before valuing it
- if (IsCoinBase() && GetBlocksToMaturity() > 0)
+ if (IsImmatureCoinBase())
return 0;
CAmount* cache = nullptr;
@@ -1985,8 +1984,7 @@ CAmount CWalletTx::GetAvailableCredit(bool fUseCache, const isminefilter& filter
CAmount CWalletTx::GetImmatureWatchOnlyCredit(const bool fUseCache) const
{
- if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain())
- {
+ if (IsImmatureCoinBase() && IsInMainChain()) {
if (fUseCache && fImmatureWatchCreditCached)
return nImmatureWatchCreditCached;
nImmatureWatchCreditCached = pwallet->GetCredit(*tx, ISMINE_WATCH_ONLY);
@@ -2199,7 +2197,7 @@ CAmount CWallet::GetLegacyBalance(const isminefilter& filter, int minDepth, cons
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;
}
@@ -2259,7 +2257,7 @@ void CWallet::AvailableCoins(std::vector<COutput> &vCoins, bool fOnlySafe, const
if (!CheckFinalTx(*pcoin->tx))
continue;
- if (pcoin->IsCoinBase() && pcoin->GetBlocksToMaturity() > 0)
+ if (pcoin->IsImmatureCoinBase())
continue;
int nDepth = pcoin->GetDepthInMainChain();
@@ -3528,7 +3526,7 @@ std::map<CTxDestination, CAmount> CWallet::GetAddressBalances()
if (!pcoin->IsTrusted())
continue;
- if (pcoin->IsCoinBase() && pcoin->GetBlocksToMaturity() > 0)
+ if (pcoin->IsImmatureCoinBase())
continue;
int nDepth = pcoin->GetDepthInMainChain();
@@ -4406,6 +4404,11 @@ int CMerkleTx::GetBlocksToMaturity() const
return std::max(0, (COINBASE_MATURITY+1) - chain_depth);
}
+bool CMerkleTx::IsImmatureCoinBase() const
+{
+ // note GetBlocksToMaturity is 0 for non-coinbase tx
+ return GetBlocksToMaturity() > 0;
+}
bool CWalletTx::AcceptToMemoryPool(const CAmount& nAbsurdFee, CValidationState& state)
{