Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 282 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::GetChainParams() 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 3,864 Lines • ▼ Show 20 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 846 Lines • Show Last 20 Lines |