Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show All 28 Lines | |||||
#include <txmempool.h> | #include <txmempool.h> | ||||
#include <ui_interface.h> | #include <ui_interface.h> | ||||
#include <util/moneystr.h> | #include <util/moneystr.h> | ||||
#include <util/system.h> | #include <util/system.h> | ||||
#include <validation.h> | #include <validation.h> | ||||
#include <wallet/coincontrol.h> | #include <wallet/coincontrol.h> | ||||
#include <wallet/coinselection.h> | #include <wallet/coinselection.h> | ||||
#include <wallet/fees.h> | #include <wallet/fees.h> | ||||
#include <wallet/finaltx.h> | |||||
#include <boost/algorithm/string/replace.hpp> | #include <boost/algorithm/string/replace.hpp> | ||||
#include <algorithm> | #include <algorithm> | ||||
#include <cassert> | #include <cassert> | ||||
#include <future> | #include <future> | ||||
static CCriticalSection cs_wallets; | static CCriticalSection cs_wallets; | ||||
▲ Show 20 Lines • Show All 2,133 Lines • ▼ Show 20 Lines | Amount CWalletTx::GetChange() const { | ||||
return nChangeCached; | return nChangeCached; | ||||
} | } | ||||
bool CWalletTx::InMempool() const { | bool CWalletTx::InMempool() const { | ||||
return fInMempool; | return fInMempool; | ||||
} | } | ||||
bool CWalletTx::IsTrusted(interfaces::Chain::Lock &locked_chain) const { | bool CWalletTx::IsTrusted(interfaces::Chain::Lock &locked_chain) const { | ||||
// Temporary, for CheckFinalTx below. Removed in upcoming commit. | // Temporary, for ContextualCheckTransactionForCurrentBlock below. Removed | ||||
// in upcoming commit. | |||||
LockAnnotation lock(::cs_main); | LockAnnotation lock(::cs_main); | ||||
// Quick answer in most cases | // Quick answer in most cases | ||||
if (!CheckFinalTx(*tx)) { | CValidationState state; | ||||
if (!ContextualCheckTransactionForCurrentBlock(Params().GetConsensus(), *tx, | |||||
state)) { | |||||
return false; | return false; | ||||
} | } | ||||
int nDepth = GetDepthInMainChain(locked_chain); | int nDepth = GetDepthInMainChain(locked_chain); | ||||
if (nDepth >= 1) { | if (nDepth >= 1) { | ||||
return true; | return true; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 193 Lines • ▼ Show 20 Lines | |||||
// Calculate total balance in a different way from GetBalance. The biggest | // Calculate total balance in a different way from GetBalance. The biggest | ||||
// difference is that GetBalance sums up all unspent TxOuts paying to the | // 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, 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 | // wallet, and then subtracts the values of TxIns spending from the wallet. This | ||||
// also has fewer restrictions on which unconfirmed transactions are considered | // also has fewer restrictions on which unconfirmed transactions are considered | ||||
// trusted. | // trusted. | ||||
Amount CWallet::GetLegacyBalance(const isminefilter &filter, | Amount CWallet::GetLegacyBalance(const isminefilter &filter, | ||||
int minDepth) const { | int minDepth) const { | ||||
// Temporary, for CheckFinalTx below. Removed in upcoming commit. | // Temporary, for ContextualCheckTransactionForCurrentBlock below. Removed | ||||
// in upcoming commit. | |||||
LockAnnotation lock(::cs_main); | LockAnnotation lock(::cs_main); | ||||
auto locked_chain = chain().lock(); | auto locked_chain = chain().lock(); | ||||
LOCK(cs_wallet); | LOCK(cs_wallet); | ||||
const Consensus::Params params = Params().GetConsensus(); | |||||
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(*locked_chain); | const int depth = wtx.GetDepthInMainChain(*locked_chain); | ||||
if (depth < 0 || !CheckFinalTx(*wtx.tx) || | CValidationState state; | ||||
if (depth < 0 || | |||||
!ContextualCheckTransactionForCurrentBlock(params, *wtx.tx, | |||||
state) || | |||||
wtx.IsImmatureCoinBase(*locked_chain)) { | wtx.IsImmatureCoinBase(*locked_chain)) { | ||||
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(); | ||||
Show All 38 Lines | void CWallet::AvailableCoins(interfaces::Chain::Lock &locked_chain, | ||||
const uint64_t nMaximumCount, const int nMinDepth, | const uint64_t nMaximumCount, const int nMinDepth, | ||||
const int nMaxDepth) const { | const int nMaxDepth) const { | ||||
AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
AssertLockHeld(cs_wallet); | AssertLockHeld(cs_wallet); | ||||
vCoins.clear(); | vCoins.clear(); | ||||
Amount nTotal = Amount::zero(); | Amount nTotal = Amount::zero(); | ||||
const Consensus::Params params = Params().GetConsensus(); | |||||
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->tx)) { | CValidationState state; | ||||
if (!ContextualCheckTransactionForCurrentBlock(params, *pcoin->tx, | |||||
state)) { | |||||
continue; | continue; | ||||
} | } | ||||
if (pcoin->IsImmatureCoinBase(locked_chain)) { | if (pcoin->IsImmatureCoinBase(locked_chain)) { | ||||
continue; | continue; | ||||
} | } | ||||
int nDepth = pcoin->GetDepthInMainChain(locked_chain); | int nDepth = pcoin->GetDepthInMainChain(locked_chain); | ||||
▲ Show 20 Lines • Show All 2,490 Lines • Show Last 20 Lines |