Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
| Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | if (request.URI.substr(0, WALLET_ENDPOINT_BASE.size()) == | ||||
| // 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 (CWalletRef pwallet : ::vpwallets) { | for (CWalletRef pwallet : ::vpwallets) { | ||||
| if (pwallet->GetName() == requestedWallet) { | if (pwallet->GetName() == requestedWallet) { | ||||
| return pwallet; | return pwallet; | ||||
| } | } | ||||
| } | } | ||||
| throw JSONRPCError(RPC_INVALID_PARAMETER, | 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 ::vpwallets.size() == 1 || (request.fHelp && ::vpwallets.size() > 0) | ||||
| ? ::vpwallets[0] | ? ::vpwallets[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; | ||||
| } | } | ||||
| throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found (disabled)"); | if (::vpwallets.empty()) { | ||||
| // Note: It isn't currently possible to trigger this error because | |||||
| // 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 | |||||
| // the future that wallet RPC methods might get or remain registered | |||||
| // when no wallets are loaded. | |||||
| throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found (wallet " | |||||
| "method is disabled because " | |||||
| "no wallet is loaded)"); | |||||
| } | |||||
| throw JSONRPCError(RPC_WALLET_NOT_SPECIFIED, | |||||
| "Wallet file not specified (must request wallet RPC " | |||||
| "through /wallet/<filename> uri-path)."); | |||||
| } | } | ||||
| void EnsureWalletIsUnlocked(CWallet *const pwallet) { | void EnsureWalletIsUnlocked(CWallet *const pwallet) { | ||||
| if (pwallet->IsLocked()) { | if (pwallet->IsLocked()) { | ||||
| throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the " | throw JSONRPCError(RPC_WALLET_UNLOCK_NEEDED, "Error: Please enter the " | ||||
| "wallet passphrase with " | "wallet passphrase with " | ||||
| "walletpassphrase first."); | "walletpassphrase first."); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 3,411 Lines • Show Last 20 Lines | |||||