| 60 | } |
| 61 | |
| 62 | std::shared_ptr<CWallet> GetWalletForJSONRPCRequest(const JSONRPCRequest& request) |
| 63 | { |
| 64 | CHECK_NONFATAL(request.mode == JSONRPCRequest::EXECUTE); |
| 65 | WalletContext& context = EnsureWalletContext(request.context); |
| 66 | |
| 67 | if (auto wallet_name{GetWalletNameFromJSONRPCRequest(request)}) { |
| 68 | std::shared_ptr<CWallet> pwallet{GetWallet(context, *wallet_name)}; |
| 69 | if (!pwallet) throw JSONRPCError(RPC_WALLET_NOT_FOUND, "Requested wallet does not exist or is not loaded"); |
| 70 | return pwallet; |
| 71 | } |
| 72 | |
| 73 | size_t count{0}; |
| 74 | auto wallet = GetDefaultWallet(context, count); |
| 75 | if (wallet) return wallet; |
| 76 | |
| 77 | if (count == 0) { |
| 78 | throw JSONRPCError( |
| 79 | 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)"); |
| 80 | } |
| 81 | throw JSONRPCError(RPC_WALLET_NOT_SPECIFIED, |
| 82 | "Multiple wallets are loaded. Please select which wallet to use by requesting the RPC through the /wallet/<walletname> URI path."); |
| 83 | } |
| 84 | |
| 85 | void EnsureWalletIsUnlocked(const CWallet& wallet) |
| 86 | { |
no test coverage detected