Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 3,162 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; | |||||
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 is invalid | // Empty string means unencrypted | ||||
throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, | warning = "Empty string given as passphrase, wallet will not be " | ||||
"Cannot encrypt a wallet with a blank password"); | "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 warning; | std::string create_warning; | ||||
std::shared_ptr<CWallet> wallet; | std::shared_ptr<CWallet> wallet; | ||||
WalletCreationStatus status = | WalletCreationStatus status = CreateWallet( | ||||
CreateWallet(config.GetChainParams(), *g_rpc_chain, passphrase, flags, | config.GetChainParams(), *g_rpc_chain, passphrase, flags, | ||||
request.params[0].get_str(), error, warning, wallet); | request.params[0].get_str(), error, create_warning, 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", warning); | ||||
return obj; | return obj; | ||||
} | } | ||||
static UniValue unloadwallet(const Config &config, | static UniValue unloadwallet(const Config &config, | ||||
▲ Show 20 Lines • Show All 1,524 Lines • Show Last 20 Lines |