| 2635 | |
| 2636 | |
| 2637 | static UniValue walletpassphrasechange(const JSONRPCRequest& request) |
| 2638 | { |
| 2639 | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); |
| 2640 | CWallet* const pwallet = wallet.get(); |
| 2641 | |
| 2642 | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
| 2643 | return NullUniValue; |
| 2644 | } |
| 2645 | |
| 2646 | if (request.fHelp || request.params.size() != 2) { |
| 2647 | throw std::runtime_error( |
| 2648 | "walletpassphrasechange \"oldpassphrase\" \"newpassphrase\"\n" |
| 2649 | "\nChanges the wallet passphrase from 'oldpassphrase' to 'newpassphrase'.\n" |
| 2650 | "\nArguments:\n" |
| 2651 | "1. \"oldpassphrase\" (string) The current passphrase\n" |
| 2652 | "2. \"newpassphrase\" (string) The new passphrase\n" |
| 2653 | "\nExamples:\n" |
| 2654 | + HelpExampleCli("walletpassphrasechange", "\"old one\" \"new one\"") |
| 2655 | + HelpExampleRpc("walletpassphrasechange", "\"old one\", \"new one\"") |
| 2656 | ); |
| 2657 | } |
| 2658 | |
| 2659 | LOCK2(cs_main, pwallet->cs_wallet); |
| 2660 | |
| 2661 | if (!pwallet->IsCrypted()) { |
| 2662 | throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletpassphrasechange was called."); |
| 2663 | } |
| 2664 | |
| 2665 | // TODO: get rid of these .c_str() calls by implementing SecureString::operator=(std::string) |
| 2666 | // Alternately, find a way to make request.params[0] mlock()'d to begin with. |
| 2667 | SecureString strOldWalletPass; |
| 2668 | strOldWalletPass.reserve(100); |
| 2669 | strOldWalletPass = request.params[0].get_str().c_str(); |
| 2670 | |
| 2671 | SecureString strNewWalletPass; |
| 2672 | strNewWalletPass.reserve(100); |
| 2673 | strNewWalletPass = request.params[1].get_str().c_str(); |
| 2674 | |
| 2675 | if (strOldWalletPass.length() < 1 || strNewWalletPass.length() < 1) |
| 2676 | throw std::runtime_error( |
| 2677 | "walletpassphrasechange <oldpassphrase> <newpassphrase>\n" |
| 2678 | "Changes the wallet passphrase from <oldpassphrase> to <newpassphrase>."); |
| 2679 | |
| 2680 | if (!pwallet->ChangeWalletPassphrase(strOldWalletPass, strNewWalletPass)) { |
| 2681 | throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect."); |
| 2682 | } |
| 2683 | |
| 2684 | return NullUniValue; |
| 2685 | } |
| 2686 | |
| 2687 | |
| 2688 | static UniValue walletlock(const JSONRPCRequest& request) |
nothing calls this directly
no test coverage detected