| 176 | |
| 177 | |
| 178 | RPCMethod walletlock() |
| 179 | { |
| 180 | return RPCMethod{ |
| 181 | "walletlock", |
| 182 | "Removes the wallet encryption key from memory, locking the wallet.\n" |
| 183 | "After calling this method, you will need to call walletpassphrase again\n" |
| 184 | "before being able to call any methods which require the wallet to be unlocked.\n", |
| 185 | {}, |
| 186 | RPCResult{RPCResult::Type::NONE, "", ""}, |
| 187 | RPCExamples{ |
| 188 | "\nSet the passphrase for 2 minutes to perform a transaction\n" |
| 189 | + HelpExampleCli("walletpassphrase", "\"my pass phrase\" 120") + |
| 190 | "\nPerform a send (requires passphrase set)\n" |
| 191 | + HelpExampleCli("sendtoaddress", "\"" + EXAMPLE_ADDRESS[0] + "\" 1.0") + |
| 192 | "\nClear the passphrase since we are done before 2 minutes is up\n" |
| 193 | + HelpExampleCli("walletlock", "") + |
| 194 | "\nAs a JSON-RPC call\n" |
| 195 | + HelpExampleRpc("walletlock", "") |
| 196 | }, |
| 197 | [](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue |
| 198 | { |
| 199 | std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request); |
| 200 | if (!pwallet) return UniValue::VNULL; |
| 201 | |
| 202 | if (!pwallet->HasEncryptionKeys()) { |
| 203 | throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletlock was called."); |
| 204 | } |
| 205 | |
| 206 | if (pwallet->IsScanningWithPassphrase()) { |
| 207 | throw JSONRPCError(RPC_WALLET_ERROR, "Error: the wallet is currently being used to rescan the blockchain for related transactions. Please call `abortrescan` before locking the wallet."); |
| 208 | } |
| 209 | |
| 210 | LOCK2(pwallet->m_relock_mutex, pwallet->cs_wallet); |
| 211 | |
| 212 | pwallet->Lock(); |
| 213 | pwallet->nRelockTime = 0; |
| 214 | |
| 215 | return UniValue::VNULL; |
| 216 | }, |
| 217 | }; |
| 218 | } |
| 219 | |
| 220 | |
| 221 | RPCMethod encryptwallet() |
nothing calls this directly
no test coverage detected