| 2093 | } |
| 2094 | |
| 2095 | UniValue walletpassphrase(const UniValue& params, bool fHelp) |
| 2096 | { |
| 2097 | if (pwalletMain->IsCrypted() && (fHelp || params.size() < 2 || params.size() > 3)) |
| 2098 | throw runtime_error( |
| 2099 | "walletpassphrase \"passphrase\" timeout ( stakingOnly )\n" |
| 2100 | "\nStores the wallet decryption key in memory for 'timeout' seconds.\n" |
| 2101 | "This is needed prior to performing transactions related to private keys such as sending LUXs\n" |
| 2102 | "\nArguments:\n" |
| 2103 | "1. \"passphrase\" (string, required) The wallet passphrase\n" |
| 2104 | "2. timeout (numeric, required) The time to keep the decryption key in seconds.\n" |
| 2105 | "3. stakingOnly (boolean, optional, default=flase) If is true sending functions are disabled." |
| 2106 | "\nNote:\n" |
| 2107 | "Issuing the walletpassphrase command while the wallet is already unlocked will set a new unlock\n" |
| 2108 | "time that overrides the old one. A timeout of \"0\" unlocks until the wallet is closed.\n" |
| 2109 | "\nExamples:\n" |
| 2110 | "\nUnlock the wallet for 60 seconds\n" + |
| 2111 | HelpExampleCli("walletpassphrase", "\"my pass phrase\" 60") + |
| 2112 | "\nUnlock the wallet for 60 seconds but allow Darksend only\n" + HelpExampleCli("walletpassphrase", "\"my pass phrase\" 60 true") + |
| 2113 | "\nLock the wallet again (before 60 seconds)\n" + HelpExampleCli("walletlock", "") + |
| 2114 | "\nAs json rpc call\n" + HelpExampleRpc("walletpassphrase", "\"my pass phrase\", 60")); |
| 2115 | |
| 2116 | LOCK2(cs_main, pwalletMain->cs_wallet); |
| 2117 | |
| 2118 | if (fHelp) |
| 2119 | return true; |
| 2120 | if (!pwalletMain->IsCrypted()) |
| 2121 | throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletpassphrase was called."); |
| 2122 | |
| 2123 | // Note that the walletpassphrase is stored in params[0] which is not mlock()ed |
| 2124 | SecureString strWalletPass; |
| 2125 | strWalletPass.reserve(100); |
| 2126 | // TODO: get rid of this .c_str() by implementing SecureString::operator=(std::string) |
| 2127 | // Alternately, find a way to make params[0] mlock()'d to begin with. |
| 2128 | strWalletPass = params[0].get_str().c_str(); |
| 2129 | |
| 2130 | bool stakingOnly = false; |
| 2131 | if (params.size() == 3) |
| 2132 | stakingOnly = params[2].get_bool(); |
| 2133 | |
| 2134 | if (!pwalletMain->IsLocked() && pwalletMain->fWalletUnlockStakingOnly && stakingOnly) |
| 2135 | throw JSONRPCError(RPC_WALLET_ALREADY_UNLOCKED, "Error: Wallet is already unlocked."); |
| 2136 | |
| 2137 | if (!pwalletMain->Unlock(strWalletPass, stakingOnly)) |
| 2138 | throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect."); |
| 2139 | |
| 2140 | pwalletMain->TopUpKeyPool(); |
| 2141 | |
| 2142 | int64_t nSleepTime = params[1].get_int64(); |
| 2143 | LOCK(cs_nWalletUnlockTime); |
| 2144 | nWalletUnlockTime = GetTime() + nSleepTime; |
| 2145 | if (nSleepTime > 0) { |
| 2146 | nWalletUnlockTime = GetTime () + nSleepTime; |
| 2147 | RPCRunLater ("lockwallet", boost::bind (LockWallet, pwalletMain), nSleepTime); |
| 2148 | } |
| 2149 | |
| 2150 | return NullUniValue; |
| 2151 | } |
| 2152 |
nothing calls this directly
no test coverage detected