Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
CWallet *GetWalletForJSONRPCRequest(const JSONRPCRequest &request) { | CWallet *GetWalletForJSONRPCRequest(const JSONRPCRequest &request) { | ||||
if (request.URI.substr(0, WALLET_ENDPOINT_BASE.size()) == | if (request.URI.substr(0, WALLET_ENDPOINT_BASE.size()) == | ||||
WALLET_ENDPOINT_BASE) { | WALLET_ENDPOINT_BASE) { | ||||
// wallet endpoint was used | // wallet endpoint was used | ||||
std::string requestedWallet = | std::string requestedWallet = | ||||
urlDecode(request.URI.substr(WALLET_ENDPOINT_BASE.size())); | urlDecode(request.URI.substr(WALLET_ENDPOINT_BASE.size())); | ||||
for (CWallet *pwallet : ::vpwallets) { | CWallet *pwallet = GetWallet(requestedWallet); | ||||
if (pwallet->GetName() == requestedWallet) { | if (!pwallet) { | ||||
return pwallet; | throw JSONRPCError( | ||||
} | RPC_WALLET_NOT_FOUND, | ||||
} | |||||
throw JSONRPCError(RPC_WALLET_NOT_FOUND, | |||||
"Requested wallet does not exist or is not loaded"); | "Requested wallet does not exist or is not loaded"); | ||||
} | } | ||||
return ::vpwallets.size() == 1 || (request.fHelp && ::vpwallets.size() > 0) | return pwallet; | ||||
? ::vpwallets[0] | } | ||||
std::vector<CWallet *> wallets = GetWallets(); | |||||
return wallets.size() == 1 || (request.fHelp && wallets.size() > 0) | |||||
? wallets[0] | |||||
: nullptr; | : nullptr; | ||||
} | } | ||||
std::string HelpRequiringPassphrase(CWallet *const pwallet) { | std::string HelpRequiringPassphrase(CWallet *const pwallet) { | ||||
return pwallet && pwallet->IsCrypted() ? "\nRequires wallet passphrase to " | return pwallet && pwallet->IsCrypted() ? "\nRequires wallet passphrase to " | ||||
"be set with walletpassphrase " | "be set with walletpassphrase " | ||||
"call." | "call." | ||||
: ""; | : ""; | ||||
} | } | ||||
bool EnsureWalletIsAvailable(CWallet *const pwallet, bool avoidException) { | bool EnsureWalletIsAvailable(CWallet *const pwallet, bool avoidException) { | ||||
if (pwallet) { | if (pwallet) { | ||||
return true; | return true; | ||||
} | } | ||||
if (avoidException) { | if (avoidException) { | ||||
return false; | return false; | ||||
} | } | ||||
if (GetWallets().empty()) { | |||||
if (::vpwallets.empty()) { | |||||
// Note: It isn't currently possible to trigger this error because | // Note: It isn't currently possible to trigger this error because | ||||
// wallet RPC methods aren't registered unless a wallet is loaded. But | // wallet RPC methods aren't registered unless a wallet is loaded. But | ||||
// this error is being kept as a precaution, because it's possible in | // this error is being kept as a precaution, because it's possible in | ||||
// the future that wallet RPC methods might get or remain registered | // the future that wallet RPC methods might get or remain registered | ||||
// when no wallets are loaded. | // when no wallets are loaded. | ||||
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found (wallet " | throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found (wallet " | ||||
"method is disabled because " | "method is disabled because " | ||||
"no wallet is loaded)"); | "no wallet is loaded)"); | ||||
▲ Show 20 Lines • Show All 3,167 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() != 0) { | ||||
"]\n" | "]\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("listwallets", "") + | HelpExampleCli("listwallets", "") + | ||||
HelpExampleRpc("listwallets", "")); | HelpExampleRpc("listwallets", "")); | ||||
} | } | ||||
UniValue obj(UniValue::VARR); | UniValue obj(UniValue::VARR); | ||||
for (CWallet *pwallet : vpwallets) { | for (CWallet *pwallet : GetWallets()) { | ||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
obj.push_back(pwallet->GetName()); | obj.push_back(pwallet->GetName()); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,017 Lines • Show Last 20 Lines |