Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 3,115 Lines • ▼ Show 20 Lines | RPCHelpMan{ | ||||
{RPCResult::Type::STR, "warning", | {RPCResult::Type::STR, "warning", | ||||
"Warning message if wallet was not loaded cleanly."}, | "Warning message if wallet was not loaded cleanly."}, | ||||
}}, | }}, | ||||
RPCExamples{HelpExampleCli("loadwallet", "\"test.dat\"") + | RPCExamples{HelpExampleCli("loadwallet", "\"test.dat\"") + | ||||
HelpExampleRpc("loadwallet", "\"test.dat\"")}, | HelpExampleRpc("loadwallet", "\"test.dat\"")}, | ||||
} | } | ||||
.Check(request); | .Check(request); | ||||
const CChainParams &chainParams = config.GetChainParams(); | |||||
WalletContext &context = EnsureWalletContext(request.context); | WalletContext &context = EnsureWalletContext(request.context); | ||||
WalletLocation location(request.params[0].get_str()); | WalletLocation location(request.params[0].get_str()); | ||||
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."); | ||||
} | } | ||||
} | } | ||||
bilingual_str error; | bilingual_str error; | ||||
std::vector<bilingual_str> warnings; | std::vector<bilingual_str> warnings; | ||||
std::shared_ptr<CWallet> const wallet = | std::shared_ptr<CWallet> const wallet = | ||||
LoadWallet(chainParams, *context.chain, location, error, warnings); | LoadWallet(*context.chain, location, error, warnings); | ||||
if (!wallet) { | if (!wallet) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, error.original); | throw JSONRPCError(RPC_WALLET_ERROR, error.original); | ||||
} | } | ||||
UniValue obj(UniValue::VOBJ); | UniValue obj(UniValue::VOBJ); | ||||
obj.pushKV("name", wallet->GetName()); | obj.pushKV("name", wallet->GetName()); | ||||
obj.pushKV("warning", Join(warnings, Untranslated("\n")).original); | obj.pushKV("warning", Join(warnings, Untranslated("\n")).original); | ||||
▲ Show 20 Lines • Show All 149 Lines • ▼ Show 20 Lines | if (!request.params[5].isNull() && request.params[5].get_bool()) { | ||||
flags |= WALLET_FLAG_DESCRIPTORS; | flags |= WALLET_FLAG_DESCRIPTORS; | ||||
warnings.emplace_back( | warnings.emplace_back( | ||||
Untranslated("Wallet is an experimental descriptor wallet")); | Untranslated("Wallet is an experimental descriptor wallet")); | ||||
} | } | ||||
bilingual_str error; | bilingual_str error; | ||||
std::shared_ptr<CWallet> wallet; | std::shared_ptr<CWallet> wallet; | ||||
WalletCreationStatus status = | WalletCreationStatus status = | ||||
CreateWallet(config.GetChainParams(), *context.chain, passphrase, flags, | CreateWallet(*context.chain, passphrase, flags, | ||||
request.params[0].get_str(), error, warnings, wallet); | request.params[0].get_str(), error, warnings, wallet); | ||||
switch (status) { | switch (status) { | ||||
case WalletCreationStatus::CREATION_FAILED: | case WalletCreationStatus::CREATION_FAILED: | ||||
throw JSONRPCError(RPC_WALLET_ERROR, error.original); | throw JSONRPCError(RPC_WALLET_ERROR, error.original); | ||||
case WalletCreationStatus::ENCRYPTION_FAILED: | case WalletCreationStatus::ENCRYPTION_FAILED: | ||||
throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, error.original); | throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, error.original); | ||||
case WalletCreationStatus::SUCCESS: | case WalletCreationStatus::SUCCESS: | ||||
break; | break; | ||||
▲ Show 20 Lines • Show All 1,665 Lines • Show Last 20 Lines |