| 53 | } |
| 54 | |
| 55 | std::shared_ptr<CWallet> GetWalletForJSONRPCRequest(const JSONRPCRequest& request) |
| 56 | { |
| 57 | CHECK_NONFATAL(request.mode == JSONRPCRequest::EXECUTE); |
| 58 | WalletContext& context = EnsureWalletContext(request.context); |
| 59 | |
| 60 | std::string wallet_name; |
| 61 | if (GetWalletNameFromJSONRPCRequest(request, wallet_name)) { |
| 62 | const std::shared_ptr<CWallet> pwallet = GetWallet(context, wallet_name); |
| 63 | if (!pwallet) throw JSONRPCError(RPC_WALLET_NOT_FOUND, "Requested wallet does not exist or is not loaded"); |
| 64 | return pwallet; |
| 65 | } |
| 66 | |
| 67 | std::vector<std::shared_ptr<CWallet>> wallets = GetWallets(context); |
| 68 | if (wallets.size() == 1) { |
| 69 | return wallets[0]; |
| 70 | } |
| 71 | |
| 72 | if (wallets.empty()) { |
| 73 | throw JSONRPCError( |
| 74 | RPC_WALLET_NOT_FOUND, "No wallet is loaded. Load a wallet using loadwallet or create a new one with createwallet. (Note: A default wallet is no longer automatically created)"); |
| 75 | } |
| 76 | throw JSONRPCError(RPC_WALLET_NOT_SPECIFIED, |
| 77 | "Wallet file not specified (must request wallet RPC through /wallet/<filename> uri-path)."); |
| 78 | } |
| 79 | |
| 80 | void EnsureWalletIsUnlocked(const CWallet& wallet) |
| 81 | { |
no test coverage detected