Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallettool.cpp
// Copyright (c) 2016-2018 The Bitcoin Core developers | // Copyright (c) 2016-2018 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <base58.h> | #include <base58.h> | ||||
#include <chainparams.h> | #include <chainparams.h> | ||||
#include <fs.h> | #include <fs.h> | ||||
#include <interfaces/chain.h> | |||||
#include <util/system.h> | #include <util/system.h> | ||||
#include <wallet/wallet.h> | #include <wallet/wallet.h> | ||||
#include <wallet/walletutil.h> | #include <wallet/walletutil.h> | ||||
#include <stdexcept> | #include <stdexcept> | ||||
namespace WalletTool { | namespace WalletTool { | ||||
// The standard wallet deleter function blocks on the validation interface | // The standard wallet deleter function blocks on the validation interface | ||||
// queue, which doesn't exist for the bitcoin-wallet. Define our own | // queue, which doesn't exist for the bitcoin-wallet. Define our own | ||||
// deleter here. | // deleter here. | ||||
static void WalletToolReleaseWallet(CWallet *wallet) { | static void WalletToolReleaseWallet(CWallet *wallet) { | ||||
wallet->WalletLogPrintf("Releasing wallet\n"); | wallet->WalletLogPrintf("Releasing wallet\n"); | ||||
wallet->Flush(); | wallet->Flush(); | ||||
delete wallet; | delete wallet; | ||||
} | } | ||||
static std::shared_ptr<CWallet> CreateWallet(const std::string &name, | static std::shared_ptr<CWallet> CreateWallet(const std::string &name, | ||||
const fs::path &path) { | const fs::path &path) { | ||||
if (fs::exists(path)) { | if (fs::exists(path)) { | ||||
tfm::format(std::cerr, "Error: File exists already\n"); | tfm::format(std::cerr, "Error: File exists already\n"); | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
// dummy chain interface | // dummy chain interface | ||||
auto chain = interfaces::MakeChain(); | |||||
std::shared_ptr<CWallet> wallet_instance( | std::shared_ptr<CWallet> wallet_instance( | ||||
new CWallet(Params(), *chain, WalletLocation(name), | new CWallet(Params(), nullptr /* chain */, WalletLocation(name), | ||||
WalletDatabase::Create(path)), | WalletDatabase::Create(path)), | ||||
WalletToolReleaseWallet); | WalletToolReleaseWallet); | ||||
bool first_run = true; | bool first_run = true; | ||||
DBErrors load_wallet_ret = wallet_instance->LoadWallet(first_run); | DBErrors load_wallet_ret = wallet_instance->LoadWallet(first_run); | ||||
if (load_wallet_ret != DBErrors::LOAD_OK) { | if (load_wallet_ret != DBErrors::LOAD_OK) { | ||||
tfm::format(std::cerr, "Error creating %s", name); | tfm::format(std::cerr, "Error creating %s", name); | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
Show All 12 Lines | |||||
static std::shared_ptr<CWallet> LoadWallet(const std::string &name, | static std::shared_ptr<CWallet> LoadWallet(const std::string &name, | ||||
const fs::path &path) { | const fs::path &path) { | ||||
if (!fs::exists(path)) { | if (!fs::exists(path)) { | ||||
tfm::format(std::cerr, "Error: Wallet files does not exist\n"); | tfm::format(std::cerr, "Error: Wallet files does not exist\n"); | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
// dummy chain interface | // dummy chain interface | ||||
auto chain = interfaces::MakeChain(); | |||||
std::shared_ptr<CWallet> wallet_instance( | std::shared_ptr<CWallet> wallet_instance( | ||||
new CWallet(Params(), *chain, WalletLocation(name), | new CWallet(Params(), nullptr /* chain */, WalletLocation(name), | ||||
WalletDatabase::Create(path)), | WalletDatabase::Create(path)), | ||||
WalletToolReleaseWallet); | WalletToolReleaseWallet); | ||||
DBErrors load_wallet_ret; | DBErrors load_wallet_ret; | ||||
try { | try { | ||||
bool first_run; | bool first_run; | ||||
load_wallet_ret = wallet_instance->LoadWallet(first_run); | load_wallet_ret = wallet_instance->LoadWallet(first_run); | ||||
} catch (const std::runtime_error &) { | } catch (const std::runtime_error &) { | ||||
tfm::format( | tfm::format( | ||||
▲ Show 20 Lines • Show All 90 Lines • Show Last 20 Lines |