Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 2,423 Lines • ▼ Show 20 Lines | Amount CWallet::GetImmatureWatchOnlyBalance() const { | ||||
for (const auto &entry : mapWallet) { | for (const auto &entry : mapWallet) { | ||||
const CWalletTx &wtx = entry.second; | const CWalletTx &wtx = entry.second; | ||||
nTotal += wtx.GetImmatureWatchOnlyCredit(*locked_chain); | nTotal += wtx.GetImmatureWatchOnlyCredit(*locked_chain); | ||||
} | } | ||||
return nTotal; | return nTotal; | ||||
} | } | ||||
// Calculate total balance in a different way from GetBalance. The biggest | |||||
// difference is that GetBalance sums up all unspent TxOuts paying to the | |||||
// wallet, while this sums up both spent and unspent TxOuts paying to the | |||||
// wallet, and then subtracts the values of TxIns spending from the wallet. This | |||||
// also has fewer restrictions on which unconfirmed transactions are considered | |||||
// trusted. | |||||
Amount CWallet::GetLegacyBalance(const isminefilter &filter, | |||||
int minDepth) const { | |||||
auto locked_chain = chain().lock(); | |||||
LOCK(cs_wallet); | |||||
const Consensus::Params params = Params().GetConsensus(); | |||||
Amount balance = Amount::zero(); | |||||
for (const auto &entry : mapWallet) { | |||||
const CWalletTx &wtx = entry.second; | |||||
const int depth = wtx.GetDepthInMainChain(*locked_chain); | |||||
CValidationState state; | |||||
if (depth < 0 || | |||||
!locked_chain->contextualCheckTransactionForCurrentBlock( | |||||
params, *wtx.tx, state) || | |||||
wtx.IsImmatureCoinBase(*locked_chain)) { | |||||
continue; | |||||
} | |||||
// Loop through tx outputs and add incoming payments. For outgoing txs, | |||||
// treat change outputs specially, as part of the amount debited. | |||||
Amount debit = wtx.GetDebit(filter); | |||||
const bool outgoing = debit > Amount::zero(); | |||||
for (const CTxOut &out : wtx.tx->vout) { | |||||
if (outgoing && IsChange(out)) { | |||||
debit -= out.nValue; | |||||
} else if (IsMine(out) & filter && depth >= minDepth) { | |||||
balance += out.nValue; | |||||
} | |||||
} | |||||
// For outgoing txs, subtract amount debited. | |||||
if (outgoing) { | |||||
balance -= debit; | |||||
} | |||||
} | |||||
return balance; | |||||
} | |||||
Amount CWallet::GetAvailableBalance(const CCoinControl *coinControl) const { | Amount CWallet::GetAvailableBalance(const CCoinControl *coinControl) const { | ||||
auto locked_chain = chain().lock(); | auto locked_chain = chain().lock(); | ||||
LOCK(cs_wallet); | LOCK(cs_wallet); | ||||
Amount balance = Amount::zero(); | Amount balance = Amount::zero(); | ||||
std::vector<COutput> vCoins; | std::vector<COutput> vCoins; | ||||
AvailableCoins(*locked_chain, vCoins, true, coinControl); | AvailableCoins(*locked_chain, vCoins, true, coinControl); | ||||
for (const COutput &out : vCoins) { | for (const COutput &out : vCoins) { | ||||
▲ Show 20 Lines • Show All 2,535 Lines • Show Last 20 Lines |