| 105 | |
| 106 | |
| 107 | RPCHelpMan walletpassphrasechange() |
| 108 | { |
| 109 | return RPCHelpMan{"walletpassphrasechange", |
| 110 | "\nChanges the wallet passphrase from 'oldpassphrase' to 'newpassphrase'.\n", |
| 111 | { |
| 112 | {"oldpassphrase", RPCArg::Type::STR, RPCArg::Optional::NO, "The current passphrase"}, |
| 113 | {"newpassphrase", RPCArg::Type::STR, RPCArg::Optional::NO, "The new passphrase"}, |
| 114 | }, |
| 115 | RPCResult{RPCResult::Type::NONE, "", ""}, |
| 116 | RPCExamples{ |
| 117 | HelpExampleCli("walletpassphrasechange", "\"old one\" \"new one\"") |
| 118 | + HelpExampleRpc("walletpassphrasechange", "\"old one\", \"new one\"") |
| 119 | }, |
| 120 | [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue |
| 121 | { |
| 122 | std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request); |
| 123 | if (!pwallet) return NullUniValue; |
| 124 | |
| 125 | LOCK(pwallet->cs_wallet); |
| 126 | |
| 127 | if (!pwallet->IsCrypted()) { |
| 128 | throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletpassphrasechange was called."); |
| 129 | } |
| 130 | |
| 131 | // TODO: get rid of these .c_str() calls by implementing SecureString::operator=(std::string) |
| 132 | // Alternately, find a way to make request.params[0] mlock()'d to begin with. |
| 133 | SecureString strOldWalletPass; |
| 134 | strOldWalletPass.reserve(100); |
| 135 | strOldWalletPass = request.params[0].get_str().c_str(); |
| 136 | |
| 137 | SecureString strNewWalletPass; |
| 138 | strNewWalletPass.reserve(100); |
| 139 | strNewWalletPass = request.params[1].get_str().c_str(); |
| 140 | |
| 141 | if (strOldWalletPass.empty() || strNewWalletPass.empty()) { |
| 142 | throw JSONRPCError(RPC_INVALID_PARAMETER, "passphrase cannot be empty"); |
| 143 | } |
| 144 | |
| 145 | if (!pwallet->ChangeWalletPassphrase(strOldWalletPass, strNewWalletPass)) { |
| 146 | throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect."); |
| 147 | } |
| 148 | |
| 149 | return NullUniValue; |
| 150 | }, |
| 151 | }; |
| 152 | } |
| 153 | |
| 154 | |
| 155 | RPCHelpMan walletlock() |
nothing calls this directly
no test coverage detected