| 2225 | |
| 2226 | |
| 2227 | UniValue encryptwallet(const UniValue& params, bool fHelp) |
| 2228 | { |
| 2229 | if (!pwalletMain->IsCrypted() && (fHelp || params.size() != 1)) |
| 2230 | throw runtime_error( |
| 2231 | "encryptwallet \"passphrase\"\n" |
| 2232 | "\nEncrypts the wallet with 'passphrase'. This is for first time encryption.\n" |
| 2233 | "After this, any calls that interact with private keys such as sending or signing \n" |
| 2234 | "will require the passphrase to be set prior the making these calls.\n" |
| 2235 | "Use the walletpassphrase call for this, and then walletlock call.\n" |
| 2236 | "If the wallet is already encrypted, use the walletpassphrasechange call.\n" |
| 2237 | "Note that this will shutdown the server.\n" |
| 2238 | "\nArguments:\n" |
| 2239 | "1. \"passphrase\" (string) The pass phrase to encrypt the wallet with. It must be at least 1 character, but should be long.\n" |
| 2240 | "\nExamples:\n" |
| 2241 | "\nEncrypt you wallet\n" + |
| 2242 | HelpExampleCli("encryptwallet", "\"my pass phrase\"") + |
| 2243 | "\nNow set the passphrase to use the wallet, such as for signing or sending LUXs\n" + HelpExampleCli("walletpassphrase", "\"my pass phrase\"") + |
| 2244 | "\nNow we can so something like sign\n" + HelpExampleCli("signmessage", "\"luxaddress\" \"test message\"") + |
| 2245 | "\nNow lock the wallet again by removing the passphrase\n" + HelpExampleCli("walletlock", "") + |
| 2246 | "\nAs a json rpc call\n" + HelpExampleRpc("encryptwallet", "\"my pass phrase\"")); |
| 2247 | |
| 2248 | LOCK2(cs_main, pwalletMain->cs_wallet); |
| 2249 | |
| 2250 | if (fHelp) |
| 2251 | return true; |
| 2252 | if (pwalletMain->IsCrypted()) |
| 2253 | throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an encrypted wallet, but encryptwallet was called."); |
| 2254 | |
| 2255 | // TODO: get rid of this .c_str() by implementing SecureString::operator=(std::string) |
| 2256 | // Alternately, find a way to make params[0] mlock()'d to begin with. |
| 2257 | SecureString strWalletPass; |
| 2258 | strWalletPass.reserve(100); |
| 2259 | strWalletPass = params[0].get_str().c_str(); |
| 2260 | |
| 2261 | if (strWalletPass.length() < 1) |
| 2262 | throw runtime_error( |
| 2263 | "encryptwallet <passphrase>\n" |
| 2264 | "Encrypts the wallet with <passphrase>."); |
| 2265 | |
| 2266 | if (!pwalletMain->EncryptWallet(strWalletPass)) |
| 2267 | throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, "Error: Failed to encrypt the wallet."); |
| 2268 | |
| 2269 | // BDB seems to have a bad habit of writing old data into |
| 2270 | // slack space in .dat files; that is bad if the old data is |
| 2271 | // unencrypted private keys. So: |
| 2272 | StartShutdown(); |
| 2273 | return "wallet encrypted; lux server stopping, restart to run with encrypted wallet. The keypool has been flushed, you need to make a new backup."; |
| 2274 | } |
| 2275 | |
| 2276 | UniValue lockunspent(const UniValue& params, bool fHelp) |
| 2277 | { |
nothing calls this directly
no test coverage detected