Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 277 Lines • ▼ Show 20 Lines | |||||
* @{ | * @{ | ||||
*/ | */ | ||||
std::string COutput::ToString() const { | std::string COutput::ToString() const { | ||||
return strprintf("COutput(%s, %d, %d) [%s]", tx->GetId().ToString(), i, | return strprintf("COutput(%s, %d, %d) [%s]", tx->GetId().ToString(), i, | ||||
nDepth, FormatMoney(tx->tx->vout[i].nValue)); | nDepth, FormatMoney(tx->tx->vout[i].nValue)); | ||||
} | } | ||||
const CChainParams &CWallet::chainParams() const { | |||||
// Get CChainParams from interfaces::Chain, unless wallet doesn't have a | |||||
// chain (i.e. bitcoin-wallet), in which case return global Params() | |||||
return m_chain ? m_chain->params() : Params(); | |||||
} | |||||
const CWalletTx *CWallet::GetWalletTx(const TxId &txid) const { | const CWalletTx *CWallet::GetWalletTx(const TxId &txid) const { | ||||
LOCK(cs_wallet); | LOCK(cs_wallet); | ||||
std::map<TxId, CWalletTx>::const_iterator it = mapWallet.find(txid); | std::map<TxId, CWalletTx>::const_iterator it = mapWallet.find(txid); | ||||
if (it == mapWallet.end()) { | if (it == mapWallet.end()) { | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
return &(it->second); | return &(it->second); | ||||
▲ Show 20 Lines • Show All 1,783 Lines • ▼ Show 20 Lines | bool CWalletTx::IsTrusted(interfaces::Chain::Lock &locked_chain) const { | ||||
return IsTrusted(locked_chain, s); | return IsTrusted(locked_chain, s); | ||||
} | } | ||||
bool CWalletTx::IsTrusted(interfaces::Chain::Lock &locked_chain, | bool CWalletTx::IsTrusted(interfaces::Chain::Lock &locked_chain, | ||||
std::set<TxId> &trusted_parents) const { | std::set<TxId> &trusted_parents) const { | ||||
// Quick answer in most cases | // Quick answer in most cases | ||||
TxValidationState state; | TxValidationState state; | ||||
if (!locked_chain.contextualCheckTransactionForCurrentBlock( | if (!locked_chain.contextualCheckTransactionForCurrentBlock( | ||||
this->pwallet->chainParams.GetConsensus(), *tx, state)) { | this->pwallet->chainParams().GetConsensus(), *tx, state)) { | ||||
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 191 Lines • ▼ Show 20 Lines | void CWallet::AvailableCoins(interfaces::Chain::Lock &locked_chain, | ||||
bool allow_used_addresses = | bool allow_used_addresses = | ||||
!IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE) || | !IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE) || | ||||
(coinControl && !coinControl->m_avoid_address_reuse); | (coinControl && !coinControl->m_avoid_address_reuse); | ||||
const int min_depth = {coinControl ? coinControl->m_min_depth | const int min_depth = {coinControl ? coinControl->m_min_depth | ||||
: DEFAULT_MIN_DEPTH}; | : DEFAULT_MIN_DEPTH}; | ||||
const int max_depth = {coinControl ? coinControl->m_max_depth | const int max_depth = {coinControl ? coinControl->m_max_depth | ||||
: DEFAULT_MAX_DEPTH}; | : DEFAULT_MAX_DEPTH}; | ||||
const Consensus::Params params = this->chainParams.GetConsensus(); | const Consensus::Params params = this->chainParams().GetConsensus(); | ||||
std::set<TxId> trusted_parents; | std::set<TxId> trusted_parents; | ||||
for (const auto &entry : mapWallet) { | for (const auto &entry : mapWallet) { | ||||
const TxId &wtxid = entry.first; | const TxId &wtxid = entry.first; | ||||
const CWalletTx &wtx = entry.second; | const CWalletTx &wtx = entry.second; | ||||
TxValidationState state; | TxValidationState state; | ||||
if (!locked_chain.contextualCheckTransactionForCurrentBlock( | if (!locked_chain.contextualCheckTransactionForCurrentBlock( | ||||
▲ Show 20 Lines • Show All 1,655 Lines • ▼ Show 20 Lines | try { | ||||
error_string = Untranslated( | error_string = Untranslated( | ||||
strprintf("Error loading wallet %s. %s", location.GetName(), | strprintf("Error loading wallet %s. %s", location.GetName(), | ||||
fsbridge::get_filesystem_error_message(e))); | fsbridge::get_filesystem_error_message(e))); | ||||
return false; | return false; | ||||
} | } | ||||
if (salvage_wallet) { | if (salvage_wallet) { | ||||
// Recover readable keypairs: | // Recover readable keypairs: | ||||
CWallet dummyWallet(chainParams, &chain, WalletLocation(), | CWallet dummyWallet(&chain, WalletLocation(), | ||||
WalletDatabase::CreateDummy()); | WalletDatabase::CreateDummy()); | ||||
std::string backup_filename; | std::string backup_filename; | ||||
// Even if we don't use this lock in this function, we want to preserve | // Even if we don't use this lock in this function, we want to preserve | ||||
// lock order in LoadToWallet if query of chain state is needed to know | // lock order in LoadToWallet if query of chain state is needed to know | ||||
// tx status. If lock can't be taken, tx confirmation status may be not | // tx status. If lock can't be taken, tx confirmation status may be not | ||||
// reliable. | // reliable. | ||||
auto locked_chain = dummyWallet.LockChain(); | auto locked_chain = dummyWallet.LockChain(); | ||||
if (!WalletBatch::Recover( | if (!WalletBatch::Recover( | ||||
Show All 16 Lines | std::shared_ptr<CWallet> CWallet::CreateWalletFromFile( | ||||
// Needed to restore wallet transaction meta data after -zapwallettxes | // Needed to restore wallet transaction meta data after -zapwallettxes | ||||
std::vector<CWalletTx> vWtx; | std::vector<CWalletTx> vWtx; | ||||
if (gArgs.GetBoolArg("-zapwallettxes", false)) { | if (gArgs.GetBoolArg("-zapwallettxes", false)) { | ||||
chain.initMessage( | chain.initMessage( | ||||
_("Zapping all transactions from wallet...").translated); | _("Zapping all transactions from wallet...").translated); | ||||
std::unique_ptr<CWallet> tempWallet = std::make_unique<CWallet>( | std::unique_ptr<CWallet> tempWallet = std::make_unique<CWallet>( | ||||
chainParams, &chain, location, | &chain, location, WalletDatabase::Create(location.GetPath())); | ||||
WalletDatabase::Create(location.GetPath())); | |||||
DBErrors nZapWalletRet = tempWallet->ZapWalletTx(vWtx); | DBErrors nZapWalletRet = tempWallet->ZapWalletTx(vWtx); | ||||
if (nZapWalletRet != DBErrors::LOAD_OK) { | if (nZapWalletRet != DBErrors::LOAD_OK) { | ||||
error = | error = | ||||
strprintf(_("Error loading %s: Wallet corrupted"), walletFile); | strprintf(_("Error loading %s: Wallet corrupted"), walletFile); | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
} | } | ||||
chain.initMessage(_("Loading wallet...").translated); | chain.initMessage(_("Loading wallet...").translated); | ||||
int64_t nStart = GetTimeMillis(); | int64_t nStart = GetTimeMillis(); | ||||
bool fFirstRun = true; | bool fFirstRun = true; | ||||
// TODO: Can't use std::make_shared because we need a custom deleter but | // TODO: Can't use std::make_shared because we need a custom deleter but | ||||
// should be possible to use std::allocate_shared. | // should be possible to use std::allocate_shared. | ||||
std::shared_ptr<CWallet> walletInstance( | std::shared_ptr<CWallet> walletInstance( | ||||
new CWallet(chainParams, &chain, location, | new CWallet(&chain, location, | ||||
WalletDatabase::Create(location.GetPath())), | WalletDatabase::Create(location.GetPath())), | ||||
ReleaseWallet); | ReleaseWallet); | ||||
DBErrors nLoadWalletRet = walletInstance->LoadWallet(fFirstRun); | DBErrors nLoadWalletRet = walletInstance->LoadWallet(fFirstRun); | ||||
if (nLoadWalletRet != DBErrors::LOAD_OK) { | if (nLoadWalletRet != DBErrors::LOAD_OK) { | ||||
if (nLoadWalletRet == DBErrors::CORRUPT) { | if (nLoadWalletRet == DBErrors::CORRUPT) { | ||||
error = | error = | ||||
strprintf(_("Error loading %s: Wallet corrupted"), walletFile); | strprintf(_("Error loading %s: Wallet corrupted"), walletFile); | ||||
return nullptr; | return nullptr; | ||||
▲ Show 20 Lines • Show All 502 Lines • Show Last 20 Lines |