Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 1,863 Lines • ▼ Show 20 Lines | if (tx->vin.empty()) { | ||||
return Amount::zero(); | return Amount::zero(); | ||||
} | } | ||||
Amount debit = Amount::zero(); | Amount debit = Amount::zero(); | ||||
if (filter & ISMINE_SPENDABLE) { | if (filter & ISMINE_SPENDABLE) { | ||||
if (fDebitCached) { | if (fDebitCached) { | ||||
debit += nDebitCached; | debit += nDebitCached; | ||||
} else { | } else { | ||||
nDebitCached = pwallet->GetDebit(*this, ISMINE_SPENDABLE); | nDebitCached = pwallet->GetDebit(*tx, ISMINE_SPENDABLE); | ||||
fDebitCached = true; | fDebitCached = true; | ||||
debit += nDebitCached; | debit += nDebitCached; | ||||
} | } | ||||
} | } | ||||
if (filter & ISMINE_WATCH_ONLY) { | if (filter & ISMINE_WATCH_ONLY) { | ||||
if (fWatchDebitCached) { | if (fWatchDebitCached) { | ||||
debit += nWatchDebitCached; | debit += nWatchDebitCached; | ||||
} else { | } else { | ||||
nWatchDebitCached = pwallet->GetDebit(*this, ISMINE_WATCH_ONLY); | nWatchDebitCached = pwallet->GetDebit(*tx, ISMINE_WATCH_ONLY); | ||||
fWatchDebitCached = true; | fWatchDebitCached = true; | ||||
debit += Amount(nWatchDebitCached); | debit += Amount(nWatchDebitCached); | ||||
} | } | ||||
} | } | ||||
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 (IsImmatureCoinBase()) { | 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; | ||||
} else { | } else { | ||||
nCreditCached = pwallet->GetCredit(*this, ISMINE_SPENDABLE); | nCreditCached = pwallet->GetCredit(*tx, ISMINE_SPENDABLE); | ||||
fCreditCached = true; | fCreditCached = true; | ||||
credit += nCreditCached; | credit += nCreditCached; | ||||
} | } | ||||
} | } | ||||
if (filter & ISMINE_WATCH_ONLY) { | if (filter & ISMINE_WATCH_ONLY) { | ||||
if (fWatchCreditCached) { | if (fWatchCreditCached) { | ||||
credit += nWatchCreditCached; | credit += nWatchCreditCached; | ||||
} else { | } else { | ||||
nWatchCreditCached = pwallet->GetCredit(*this, ISMINE_WATCH_ONLY); | nWatchCreditCached = pwallet->GetCredit(*tx, ISMINE_WATCH_ONLY); | ||||
fWatchCreditCached = true; | fWatchCreditCached = true; | ||||
credit += nWatchCreditCached; | credit += nWatchCreditCached; | ||||
} | } | ||||
} | } | ||||
return credit; | return credit; | ||||
} | } | ||||
Amount CWalletTx::GetImmatureCredit(bool fUseCache) const { | Amount CWalletTx::GetImmatureCredit(bool fUseCache) const { | ||||
if (IsImmatureCoinBase() && IsInMainChain()) { | if (IsImmatureCoinBase() && IsInMainChain()) { | ||||
if (fUseCache && fImmatureCreditCached) { | if (fUseCache && fImmatureCreditCached) { | ||||
return nImmatureCreditCached; | return nImmatureCreditCached; | ||||
} | } | ||||
nImmatureCreditCached = pwallet->GetCredit(*this, ISMINE_SPENDABLE); | nImmatureCreditCached = pwallet->GetCredit(*tx, 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 { | ||||
Show All 29 Lines | |||||
} | } | ||||
Amount CWalletTx::GetImmatureWatchOnlyCredit(const bool fUseCache) const { | Amount CWalletTx::GetImmatureWatchOnlyCredit(const bool fUseCache) const { | ||||
if (IsImmatureCoinBase() && IsInMainChain()) { | if (IsImmatureCoinBase() && IsInMainChain()) { | ||||
if (fUseCache && fImmatureWatchCreditCached) { | if (fUseCache && fImmatureWatchCreditCached) { | ||||
return nImmatureWatchCreditCached; | return nImmatureWatchCreditCached; | ||||
} | } | ||||
nImmatureWatchCreditCached = | nImmatureWatchCreditCached = pwallet->GetCredit(*tx, ISMINE_WATCH_ONLY); | ||||
pwallet->GetCredit(*this, ISMINE_WATCH_ONLY); | |||||
fImmatureWatchCreditCached = true; | fImmatureWatchCreditCached = true; | ||||
return nImmatureWatchCreditCached; | return nImmatureWatchCreditCached; | ||||
} | } | ||||
return Amount::zero(); | return Amount::zero(); | ||||
} | } | ||||
Amount CWalletTx::GetAvailableWatchOnlyCredit(const bool fUseCache) const { | Amount CWalletTx::GetAvailableWatchOnlyCredit(const bool fUseCache) const { | ||||
Show All 28 Lines | Amount CWalletTx::GetAvailableWatchOnlyCredit(const bool fUseCache) const { | ||||
return nCredit; | return nCredit; | ||||
} | } | ||||
Amount CWalletTx::GetChange() const { | Amount CWalletTx::GetChange() const { | ||||
if (fChangeCached) { | if (fChangeCached) { | ||||
return nChangeCached; | return nChangeCached; | ||||
} | } | ||||
nChangeCached = pwallet->GetChange(*this); | nChangeCached = pwallet->GetChange(*tx); | ||||
fChangeCached = true; | fChangeCached = true; | ||||
return nChangeCached; | return nChangeCached; | ||||
} | } | ||||
bool CWalletTx::InMempool() const { | bool CWalletTx::InMempool() const { | ||||
return fInMempool; | return fInMempool; | ||||
} | } | ||||
bool CWalletTx::IsTrusted() const { | bool CWalletTx::IsTrusted() const { | ||||
// Quick answer in most cases | // Quick answer in most cases | ||||
if (!CheckFinalTx(*this)) { | if (!CheckFinalTx(*tx)) { | ||||
return false; | return false; | ||||
} | } | ||||
int nDepth = GetDepthInMainChain(); | int nDepth = GetDepthInMainChain(); | ||||
if (nDepth >= 1) { | if (nDepth >= 1) { | ||||
return true; | return true; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 261 Lines • ▼ Show 20 Lines | void CWallet::AvailableCoins(std::vector<COutput> &vCoins, bool fOnlySafe, | ||||
vCoins.clear(); | vCoins.clear(); | ||||
Amount nTotal = Amount::zero(); | Amount nTotal = Amount::zero(); | ||||
LOCK2(cs_main, cs_wallet); | LOCK2(cs_main, cs_wallet); | ||||
for (const auto &entry : mapWallet) { | for (const auto &entry : mapWallet) { | ||||
const TxId &wtxid = entry.first; | const TxId &wtxid = entry.first; | ||||
const CWalletTx *pcoin = &entry.second; | const CWalletTx *pcoin = &entry.second; | ||||
if (!CheckFinalTx(*pcoin)) { | if (!CheckFinalTx(*pcoin->tx)) { | ||||
continue; | continue; | ||||
} | } | ||||
if (pcoin->IsImmatureCoinBase()) { | if (pcoin->IsImmatureCoinBase()) { | ||||
continue; | continue; | ||||
} | } | ||||
int nDepth = pcoin->GetDepthInMainChain(); | int nDepth = pcoin->GetDepthInMainChain(); | ||||
▲ Show 20 Lines • Show All 2,150 Lines • Show Last 20 Lines |