Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 1,825 Lines • ▼ Show 20 Lines | Amount CWalletTx::GetDebit(const isminefilter &filter) const { | ||||
} | } | ||||
return debit; | return debit; | ||||
} | } | ||||
Amount CWalletTx::GetCredit(const isminefilter &filter) const { | Amount CWalletTx::GetCredit(const isminefilter &filter) const { | ||||
// Must wait until coinbase is safely deep enough in the chain before | // Must wait until coinbase is safely deep enough in the chain before | ||||
// valuing it. | // valuing it. | ||||
if (IsCoinBase() && GetBlocksToMaturity() > 0) { | if (IsImmatureCoinBase()) { | ||||
return Amount::zero(); | return Amount::zero(); | ||||
} | } | ||||
Amount credit = Amount::zero(); | Amount credit = Amount::zero(); | ||||
if (filter & ISMINE_SPENDABLE) { | if (filter & ISMINE_SPENDABLE) { | ||||
// GetBalance can assume transactions in mapWallet won't change. | // GetBalance can assume transactions in mapWallet won't change. | ||||
if (fCreditCached) { | if (fCreditCached) { | ||||
credit += nCreditCached; | credit += nCreditCached; | ||||
Show All 13 Lines | if (filter & ISMINE_WATCH_ONLY) { | ||||
credit += nWatchCreditCached; | credit += nWatchCreditCached; | ||||
} | } | ||||
} | } | ||||
return credit; | return credit; | ||||
} | } | ||||
Amount CWalletTx::GetImmatureCredit(bool fUseCache) const { | Amount CWalletTx::GetImmatureCredit(bool fUseCache) const { | ||||
if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain()) { | if (IsImmatureCoinBase() && IsInMainChain()) { | ||||
if (fUseCache && fImmatureCreditCached) { | if (fUseCache && fImmatureCreditCached) { | ||||
return nImmatureCreditCached; | return nImmatureCreditCached; | ||||
} | } | ||||
nImmatureCreditCached = pwallet->GetCredit(*this, ISMINE_SPENDABLE); | nImmatureCreditCached = pwallet->GetCredit(*this, ISMINE_SPENDABLE); | ||||
fImmatureCreditCached = true; | fImmatureCreditCached = true; | ||||
return nImmatureCreditCached; | return nImmatureCreditCached; | ||||
} | } | ||||
return Amount::zero(); | return Amount::zero(); | ||||
} | } | ||||
Amount CWalletTx::GetAvailableCredit(bool fUseCache) const { | Amount CWalletTx::GetAvailableCredit(bool fUseCache) const { | ||||
if (pwallet == 0) { | if (pwallet == 0) { | ||||
return Amount::zero(); | return Amount::zero(); | ||||
} | } | ||||
// Must wait until coinbase is safely deep enough in the chain before | // Must wait until coinbase is safely deep enough in the chain before | ||||
// valuing it. | // valuing it. | ||||
if (IsCoinBase() && GetBlocksToMaturity() > 0) { | if (IsImmatureCoinBase()) { | ||||
return Amount::zero(); | return Amount::zero(); | ||||
} | } | ||||
if (fUseCache && fAvailableCreditCached) { | if (fUseCache && fAvailableCreditCached) { | ||||
return nAvailableCreditCached; | return nAvailableCreditCached; | ||||
} | } | ||||
Amount nCredit = Amount::zero(); | Amount nCredit = Amount::zero(); | ||||
Show All 9 Lines | Amount CWalletTx::GetAvailableCredit(bool fUseCache) const { | ||||
} | } | ||||
nAvailableCreditCached = nCredit; | nAvailableCreditCached = nCredit; | ||||
fAvailableCreditCached = true; | fAvailableCreditCached = true; | ||||
return nCredit; | return nCredit; | ||||
} | } | ||||
Amount CWalletTx::GetImmatureWatchOnlyCredit(const bool &fUseCache) const { | Amount CWalletTx::GetImmatureWatchOnlyCredit(const bool &fUseCache) const { | ||||
if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain()) { | if (IsImmatureCoinBase() && IsInMainChain()) { | ||||
if (fUseCache && fImmatureWatchCreditCached) { | if (fUseCache && fImmatureWatchCreditCached) { | ||||
return nImmatureWatchCreditCached; | return nImmatureWatchCreditCached; | ||||
} | } | ||||
nImmatureWatchCreditCached = | nImmatureWatchCreditCached = | ||||
pwallet->GetCredit(*this, ISMINE_WATCH_ONLY); | pwallet->GetCredit(*this, ISMINE_WATCH_ONLY); | ||||
fImmatureWatchCreditCached = true; | fImmatureWatchCreditCached = true; | ||||
return nImmatureWatchCreditCached; | return nImmatureWatchCreditCached; | ||||
▲ Show 20 Lines • Show All 267 Lines • ▼ Show 20 Lines | |||||
Amount CWallet::GetLegacyBalance(const isminefilter &filter, int minDepth, | Amount CWallet::GetLegacyBalance(const isminefilter &filter, int minDepth, | ||||
const std::string *account) const { | const std::string *account) const { | ||||
LOCK2(cs_main, cs_wallet); | LOCK2(cs_main, cs_wallet); | ||||
Amount balance = Amount::zero(); | Amount balance = Amount::zero(); | ||||
for (const auto &entry : mapWallet) { | for (const auto &entry : mapWallet) { | ||||
const CWalletTx &wtx = entry.second; | const CWalletTx &wtx = entry.second; | ||||
const int depth = wtx.GetDepthInMainChain(); | const int depth = wtx.GetDepthInMainChain(); | ||||
if (depth < 0 || !CheckFinalTx(*wtx.tx) || | if (depth < 0 || !CheckFinalTx(*wtx.tx) || wtx.IsImmatureCoinBase()) { | ||||
wtx.GetBlocksToMaturity() > 0) { | |||||
continue; | continue; | ||||
} | } | ||||
// Loop through tx outputs and add incoming payments. For outgoing txs, | // Loop through tx outputs and add incoming payments. For outgoing txs, | ||||
// treat change outputs specially, as part of the amount debited. | // treat change outputs specially, as part of the amount debited. | ||||
Amount debit = wtx.GetDebit(filter); | Amount debit = wtx.GetDebit(filter); | ||||
const bool outgoing = debit > Amount::zero(); | const bool outgoing = debit > Amount::zero(); | ||||
for (const CTxOut &out : wtx.tx->vout) { | for (const CTxOut &out : wtx.tx->vout) { | ||||
Show All 34 Lines | for (std::map<TxId, CWalletTx>::const_iterator it = mapWallet.begin(); | ||||
it != mapWallet.end(); ++it) { | it != mapWallet.end(); ++it) { | ||||
const TxId &wtxid = it->first; | const TxId &wtxid = it->first; | ||||
const CWalletTx *pcoin = &(*it).second; | const CWalletTx *pcoin = &(*it).second; | ||||
if (!CheckFinalTx(*pcoin)) { | if (!CheckFinalTx(*pcoin)) { | ||||
continue; | continue; | ||||
} | } | ||||
if (pcoin->IsCoinBase() && pcoin->GetBlocksToMaturity() > 0) { | if (pcoin->IsImmatureCoinBase()) { | ||||
continue; | continue; | ||||
} | } | ||||
int nDepth = pcoin->GetDepthInMainChain(); | int nDepth = pcoin->GetDepthInMainChain(); | ||||
if (nDepth < 0) { | if (nDepth < 0) { | ||||
continue; | continue; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,263 Lines • ▼ Show 20 Lines | std::map<CTxDestination, Amount> CWallet::GetAddressBalances() { | ||||
LOCK(cs_wallet); | LOCK(cs_wallet); | ||||
for (std::pair<TxId, CWalletTx> walletEntry : mapWallet) { | for (std::pair<TxId, CWalletTx> walletEntry : mapWallet) { | ||||
CWalletTx *pcoin = &walletEntry.second; | CWalletTx *pcoin = &walletEntry.second; | ||||
if (!pcoin->IsTrusted()) { | if (!pcoin->IsTrusted()) { | ||||
continue; | continue; | ||||
} | } | ||||
if (pcoin->IsCoinBase() && pcoin->GetBlocksToMaturity() > 0) { | if (pcoin->IsImmatureCoinBase()) { | ||||
continue; | continue; | ||||
} | } | ||||
int nDepth = pcoin->GetDepthInMainChain(); | int nDepth = pcoin->GetDepthInMainChain(); | ||||
if (nDepth < (pcoin->IsFromMe(ISMINE_ALL) ? 0 : 1)) { | if (nDepth < (pcoin->IsFromMe(ISMINE_ALL) ? 0 : 1)) { | ||||
continue; | continue; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 714 Lines • ▼ Show 20 Lines | |||||
int CMerkleTx::GetBlocksToMaturity() const { | int CMerkleTx::GetBlocksToMaturity() const { | ||||
if (!IsCoinBase()) { | if (!IsCoinBase()) { | ||||
return 0; | return 0; | ||||
} | } | ||||
return std::max(0, (COINBASE_MATURITY + 1) - GetDepthInMainChain()); | 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, | bool CMerkleTx::AcceptToMemoryPool(const Amount nAbsurdFee, | ||||
CValidationState &state) { | CValidationState &state) { | ||||
return ::AcceptToMemoryPool(GetConfig(), mempool, state, tx, true, nullptr, | return ::AcceptToMemoryPool(GetConfig(), mempool, state, tx, true, nullptr, | ||||
false, nAbsurdFee); | false, nAbsurdFee); | ||||
} | } |