Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show All 15 Lines | |||||
#include <policy/fees.h> | #include <policy/fees.h> | ||||
#include <rpc/rawtransaction_util.h> | #include <rpc/rawtransaction_util.h> | ||||
#include <rpc/server.h> | #include <rpc/server.h> | ||||
#include <rpc/util.h> | #include <rpc/util.h> | ||||
#include <script/descriptor.h> | #include <script/descriptor.h> | ||||
#include <util/bip32.h> | #include <util/bip32.h> | ||||
#include <util/error.h> | #include <util/error.h> | ||||
#include <util/moneystr.h> | #include <util/moneystr.h> | ||||
#include <util/string.h> | |||||
#include <util/system.h> | #include <util/system.h> | ||||
#include <util/url.h> | #include <util/url.h> | ||||
#include <util/validation.h> | #include <util/validation.h> | ||||
#include <validation.h> | #include <validation.h> | ||||
#include <wallet/coincontrol.h> | #include <wallet/coincontrol.h> | ||||
#include <wallet/psbtwallet.h> | #include <wallet/psbtwallet.h> | ||||
#include <wallet/rpcwallet.h> | #include <wallet/rpcwallet.h> | ||||
#include <wallet/wallet.h> | #include <wallet/wallet.h> | ||||
▲ Show 20 Lines • Show All 2,996 Lines • ▼ Show 20 Lines | if (!location.Exists()) { | ||||
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 error, warning; | std::string error; | ||||
std::vector<std::string> warning; | |||||
std::shared_ptr<CWallet> const wallet = | std::shared_ptr<CWallet> const wallet = | ||||
LoadWallet(chainParams, *g_rpc_chain, location, error, warning); | LoadWallet(chainParams, *g_rpc_chain, location, error, warning); | ||||
if (!wallet) { | if (!wallet) { | ||||
throw JSONRPCError(RPC_WALLET_ERROR, error); | throw JSONRPCError(RPC_WALLET_ERROR, error); | ||||
} | } | ||||
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", Join(warning, "\n")); | ||||
return obj; | return obj; | ||||
} | } | ||||
static UniValue setwalletflag(const Config &config, | static UniValue setwalletflag(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||||
CWallet *const pwallet = wallet.get(); | CWallet *const pwallet = wallet.get(); | ||||
▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | static UniValue createwallet(const Config &config, | ||||
} | } | ||||
if (!request.params[2].isNull() && request.params[2].get_bool()) { | if (!request.params[2].isNull() && request.params[2].get_bool()) { | ||||
flags |= WALLET_FLAG_BLANK_WALLET; | flags |= WALLET_FLAG_BLANK_WALLET; | ||||
} | } | ||||
SecureString passphrase; | SecureString passphrase; | ||||
passphrase.reserve(100); | passphrase.reserve(100); | ||||
std::string warning; | std::vector<std::string> warnings; | ||||
if (!request.params[3].isNull()) { | if (!request.params[3].isNull()) { | ||||
passphrase = request.params[3].get_str().c_str(); | passphrase = request.params[3].get_str().c_str(); | ||||
if (passphrase.empty()) { | if (passphrase.empty()) { | ||||
// Empty string means unencrypted | // Empty string is invalid | ||||
Fabien: Previous comment seems more accurate, and this change is not from the PR | |||||
warning = "Empty string given as passphrase, wallet will not be " | warnings.emplace_back("Empty string given as passphrase, wallet " | ||||
"encrypted."; | "will not be encrypted."); | ||||
} | } | ||||
} | } | ||||
if (!request.params[4].isNull() && request.params[4].get_bool()) { | if (!request.params[4].isNull() && request.params[4].get_bool()) { | ||||
flags |= WALLET_FLAG_AVOID_REUSE; | flags |= WALLET_FLAG_AVOID_REUSE; | ||||
} | } | ||||
std::string error; | std::string error; | ||||
std::string create_warning; | |||||
std::shared_ptr<CWallet> wallet; | std::shared_ptr<CWallet> wallet; | ||||
WalletCreationStatus status = CreateWallet( | WalletCreationStatus status = | ||||
config.GetChainParams(), *g_rpc_chain, passphrase, flags, | CreateWallet(config.GetChainParams(), *g_rpc_chain, passphrase, flags, | ||||
request.params[0].get_str(), error, create_warning, 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); | throw JSONRPCError(RPC_WALLET_ERROR, error); | ||||
case WalletCreationStatus::ENCRYPTION_FAILED: | case WalletCreationStatus::ENCRYPTION_FAILED: | ||||
throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, error); | throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, error); | ||||
case WalletCreationStatus::SUCCESS: | case WalletCreationStatus::SUCCESS: | ||||
break; | break; | ||||
// no default case, so the compiler can warn about missing cases | // no default case, so the compiler can warn about missing cases | ||||
} | } | ||||
if (warning.empty()) { | |||||
warning = create_warning; | |||||
} else if (!warning.empty() && !create_warning.empty()) { | |||||
warning += "; " + create_warning; | |||||
} | |||||
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", Join(warnings, "\n")); | ||||
return obj; | return obj; | ||||
} | } | ||||
static UniValue unloadwallet(const Config &config, | static UniValue unloadwallet(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
RPCHelpMan{ | RPCHelpMan{ | ||||
"unloadwallet", | "unloadwallet", | ||||
▲ Show 20 Lines • Show All 1,521 Lines • Show Last 20 Lines |
Previous comment seems more accurate, and this change is not from the PR