| 2686 | |
| 2687 | |
| 2688 | static UniValue walletlock(const JSONRPCRequest& request) |
| 2689 | { |
| 2690 | std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); |
| 2691 | CWallet* const pwallet = wallet.get(); |
| 2692 | |
| 2693 | if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { |
| 2694 | return NullUniValue; |
| 2695 | } |
| 2696 | |
| 2697 | if (request.fHelp || request.params.size() != 0) { |
| 2698 | throw std::runtime_error( |
| 2699 | "walletlock\n" |
| 2700 | "\nRemoves the wallet encryption key from memory, locking the wallet.\n" |
| 2701 | "After calling this method, you will need to call walletpassphrase again\n" |
| 2702 | "before being able to call any methods which require the wallet to be unlocked.\n" |
| 2703 | "\nExamples:\n" |
| 2704 | "\nSet the passphrase for 2 minutes to perform a transaction\n" |
| 2705 | + HelpExampleCli("walletpassphrase", "\"my pass phrase\" 120") + |
| 2706 | "\nPerform a send (requires passphrase set)\n" |
| 2707 | + HelpExampleCli("sendtoaddress", "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 1.0") + |
| 2708 | "\nClear the passphrase since we are done before 2 minutes is up\n" |
| 2709 | + HelpExampleCli("walletlock", "") + |
| 2710 | "\nAs json rpc call\n" |
| 2711 | + HelpExampleRpc("walletlock", "") |
| 2712 | ); |
| 2713 | } |
| 2714 | |
| 2715 | LOCK2(cs_main, pwallet->cs_wallet); |
| 2716 | |
| 2717 | if (!pwallet->IsCrypted()) { |
| 2718 | throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletlock was called."); |
| 2719 | } |
| 2720 | |
| 2721 | pwallet->Lock(); |
| 2722 | pwallet->nRelockTime = 0; |
| 2723 | |
| 2724 | return NullUniValue; |
| 2725 | } |
| 2726 | |
| 2727 | |
| 2728 | static UniValue encryptwallet(const JSONRPCRequest& request) |
nothing calls this directly
no test coverage detected