Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 3,110 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() != 1) { | ||||
HelpExampleRpc("loadwallet", "\"test.dat\"")}, | HelpExampleRpc("loadwallet", "\"test.dat\"")}, | ||||
} | } | ||||
.ToString()); | .ToString()); | ||||
} | } | ||||
const CChainParams &chainParams = config.GetChainParams(); | const CChainParams &chainParams = config.GetChainParams(); | ||||
WalletLocation location(request.params[0].get_str()); | WalletLocation location(request.params[0].get_str()); | ||||
std::string error; | |||||
if (!location.Exists()) { | if (!location.Exists()) { | ||||
throw JSONRPCError(RPC_WALLET_NOT_FOUND, | throw JSONRPCError(RPC_WALLET_NOT_FOUND, | ||||
"Wallet " + location.GetName() + " not found."); | "Wallet " + location.GetName() + " not found."); | ||||
} else if (fs::is_directory(location.GetPath())) { | } else if (fs::is_directory(location.GetPath())) { | ||||
// The given filename is a directory. Check that there's a wallet.dat | // The given filename is a directory. Check that there's a wallet.dat | ||||
// file. | // file. | ||||
fs::path wallet_dat_file = location.GetPath() / "wallet.dat"; | fs::path wallet_dat_file = location.GetPath() / "wallet.dat"; | ||||
if (fs::symlink_status(wallet_dat_file).type() == fs::file_not_found) { | if (fs::symlink_status(wallet_dat_file).type() == fs::file_not_found) { | ||||
throw JSONRPCError(RPC_WALLET_NOT_FOUND, | throw JSONRPCError(RPC_WALLET_NOT_FOUND, | ||||
"Directory " + location.GetName() + | "Directory " + location.GetName() + | ||||
" does not contain a wallet.dat file."); | " does not contain a wallet.dat file."); | ||||
} | } | ||||
} | } | ||||
std::string warning; | std::string error, warning; | ||||
if (!CWallet::Verify(chainParams, *g_rpc_interfaces->chain, location, false, | std::shared_ptr<CWallet> const wallet = LoadWallet( | ||||
error, warning)) { | chainParams, *g_rpc_interfaces->chain, location, error, warning); | ||||
throw JSONRPCError(RPC_WALLET_ERROR, | |||||
"Wallet file verification failed: " + error); | |||||
} | |||||
std::shared_ptr<CWallet> const wallet = CWallet::CreateWalletFromFile( | |||||
chainParams, *g_rpc_interfaces->chain, location); | |||||
if (!wallet) { | if (!wallet) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, "Wallet loading failed."); | throw JSONRPCError(RPC_WALLET_ERROR, error); | ||||
} | } | ||||
AddWallet(wallet); | |||||
wallet->postInitProcess(); | |||||
UniValue obj(UniValue::VOBJ); | UniValue obj(UniValue::VOBJ); | ||||
obj.pushKV("name", wallet->GetName()); | obj.pushKV("name", wallet->GetName()); | ||||
obj.pushKV("warning", warning); | obj.pushKV("warning", warning); | ||||
return obj; | return obj; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,731 Lines • Show Last 20 Lines |