Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 3,725 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() != 1) { | ||||
"}\n" | "}\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("loadwallet", "\"test.dat\"") + | HelpExampleCli("loadwallet", "\"test.dat\"") + | ||||
HelpExampleRpc("loadwallet", "\"test.dat\"")); | HelpExampleRpc("loadwallet", "\"test.dat\"")); | ||||
} | } | ||||
const CChainParams &chainParams = config.GetChainParams(); | const CChainParams &chainParams = config.GetChainParams(); | ||||
std::string wallet_file = request.params[0].get_str(); | WalletLocation location(request.params[0].get_str()); | ||||
std::string error; | std::string error; | ||||
fs::path wallet_path = fs::absolute(wallet_file, GetWalletDir()); | if (!location.Exists()) { | ||||
if (fs::symlink_status(wallet_path).type() == fs::file_not_found) { | |||||
throw JSONRPCError(RPC_WALLET_NOT_FOUND, | throw JSONRPCError(RPC_WALLET_NOT_FOUND, | ||||
"Wallet " + wallet_file + " not found."); | "Wallet " + location.GetName() + " not found."); | ||||
} else if (fs::is_directory(wallet_path)) { | } 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 = wallet_path / "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 " + wallet_file + | "Directory " + location.GetName() + | ||||
" does not contain a wallet.dat file."); | " does not contain a wallet.dat file."); | ||||
} | } | ||||
} | } | ||||
std::string warning; | std::string warning; | ||||
if (!CWallet::Verify(chainParams, wallet_file, false, error, warning)) { | if (!CWallet::Verify(chainParams, location, false, error, warning)) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, | throw JSONRPCError(RPC_WALLET_ERROR, | ||||
"Wallet file verification failed: " + error); | "Wallet file verification failed: " + error); | ||||
} | } | ||||
std::shared_ptr<CWallet> const wallet = CWallet::CreateWalletFromFile( | std::shared_ptr<CWallet> const wallet = | ||||
chainParams, wallet_file, fs::absolute(wallet_file, GetWalletDir())); | CWallet::CreateWalletFromFile(chainParams, location); | ||||
if (!wallet) { | if (!wallet) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, "Wallet loading failed."); | throw JSONRPCError(RPC_WALLET_ERROR, "Wallet loading failed."); | ||||
} | } | ||||
AddWallet(wallet); | AddWallet(wallet); | ||||
wallet->postInitProcess(); | wallet->postInitProcess(); | ||||
UniValue obj(UniValue::VOBJ); | UniValue obj(UniValue::VOBJ); | ||||
Show All 27 Lines | if (request.fHelp || request.params.size() < 1 || | ||||
"}\n" | "}\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("createwallet", "\"testwallet\"") + | HelpExampleCli("createwallet", "\"testwallet\"") + | ||||
HelpExampleRpc("createwallet", "\"testwallet\"")); | HelpExampleRpc("createwallet", "\"testwallet\"")); | ||||
} | } | ||||
const CChainParams &chainParams = config.GetChainParams(); | const CChainParams &chainParams = config.GetChainParams(); | ||||
std::string wallet_name = request.params[0].get_str(); | |||||
std::string error; | std::string error; | ||||
std::string warning; | std::string warning; | ||||
bool disable_privatekeys = false; | bool disable_privatekeys = false; | ||||
if (!request.params[1].isNull()) { | if (!request.params[1].isNull()) { | ||||
disable_privatekeys = request.params[1].get_bool(); | disable_privatekeys = request.params[1].get_bool(); | ||||
} | } | ||||
fs::path wallet_path = fs::absolute(wallet_name, GetWalletDir()); | WalletLocation location(request.params[0].get_str()); | ||||
if (fs::symlink_status(wallet_path).type() != fs::file_not_found) { | if (location.Exists()) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, | throw JSONRPCError(RPC_WALLET_ERROR, | ||||
"Wallet " + wallet_name + " already exists."); | "Wallet " + location.GetName() + " already exists."); | ||||
} | } | ||||
// Wallet::Verify will check if we're trying to create a wallet with a | // Wallet::Verify will check if we're trying to create a wallet with a | ||||
// duplicate name. | // duplicate name. | ||||
if (!CWallet::Verify(chainParams, wallet_name, false, error, warning)) { | if (!CWallet::Verify(chainParams, location, false, error, warning)) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, | throw JSONRPCError(RPC_WALLET_ERROR, | ||||
"Wallet file verification failed: " + error); | "Wallet file verification failed: " + error); | ||||
} | } | ||||
std::shared_ptr<CWallet> const wallet = CWallet::CreateWalletFromFile( | std::shared_ptr<CWallet> const wallet = CWallet::CreateWalletFromFile( | ||||
chainParams, wallet_name, fs::absolute(wallet_name, GetWalletDir()), | chainParams, location, | ||||
(disable_privatekeys ? uint64_t(WALLET_FLAG_DISABLE_PRIVATE_KEYS) : 0)); | (disable_privatekeys ? uint64_t(WALLET_FLAG_DISABLE_PRIVATE_KEYS) : 0)); | ||||
if (!wallet) { | if (!wallet) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, "Wallet creation failed."); | throw JSONRPCError(RPC_WALLET_ERROR, "Wallet creation failed."); | ||||
} | } | ||||
AddWallet(wallet); | AddWallet(wallet); | ||||
wallet->postInitProcess(); | wallet->postInitProcess(); | ||||
▲ Show 20 Lines • Show All 1,625 Lines • Show Last 20 Lines |