14 "\nStores the wallet decryption key in memory for 'timeout' seconds.\n" 15 "This is needed prior to performing transactions related to private keys such as sending bitcoins\n" 17 "Issuing the walletpassphrase command while the wallet is already unlocked will set a new unlock\n" 18 "time that overrides the old one.\n",
25 "\nUnlock the wallet for 60 seconds\n" 27 "\nLock the wallet again (before 60 seconds)\n" 29 "\nAs a JSON-RPC call\n" 51 strWalletPass.reserve(100);
54 strWalletPass = request.params[0].get_str().c_str();
57 nSleepTime = request.params[1].getInt<int64_t>();
63 constexpr int64_t MAX_SLEEP_TIME = 100000000;
64 if (nSleepTime > MAX_SLEEP_TIME) {
65 nSleepTime = MAX_SLEEP_TIME;
68 if (strWalletPass.empty()) {
72 if (!pwallet->
Unlock(strWalletPass)) {
78 pwallet->nRelockTime =
GetTime() + nSleepTime;
79 relock_time = pwallet->nRelockTime;
90 std::weak_ptr<CWallet> weak_wallet =
wallet;
92 if (
auto shared_wallet = weak_wallet.lock()) {
93 LOCK(shared_wallet->cs_wallet);
95 if (shared_wallet->nRelockTime != relock_time)
return;
96 shared_wallet->Lock();
97 shared_wallet->nRelockTime = 0;
110 "\nChanges the wallet passphrase from 'oldpassphrase' to 'newpassphrase'.\n",
117 HelpExampleCli(
"walletpassphrasechange",
"\"old one\" \"new one\"")
118 +
HelpExampleRpc(
"walletpassphrasechange",
"\"old one\", \"new one\"")
125 LOCK(pwallet->cs_wallet);
127 if (!pwallet->IsCrypted()) {
134 strOldWalletPass.reserve(100);
135 strOldWalletPass = request.params[0].get_str().c_str();
138 strNewWalletPass.reserve(100);
139 strNewWalletPass = request.params[1].get_str().c_str();
141 if (strOldWalletPass.empty() || strNewWalletPass.empty()) {
145 if (!pwallet->ChangeWalletPassphrase(strOldWalletPass, strNewWalletPass)) {
158 "\nRemoves the wallet encryption key from memory, locking the wallet.\n" 159 "After calling this method, you will need to call walletpassphrase again\n" 160 "before being able to call any methods which require the wallet to be unlocked.\n",
164 "\nSet the passphrase for 2 minutes to perform a transaction\n" 166 "\nPerform a send (requires passphrase set)\n" 168 "\nClear the passphrase since we are done before 2 minutes is up\n" 170 "\nAs a JSON-RPC call\n" 178 LOCK(pwallet->cs_wallet);
180 if (!pwallet->IsCrypted()) {
185 pwallet->nRelockTime = 0;
196 "\nEncrypts the wallet with 'passphrase'. This is for first time encryption.\n" 197 "After this, any calls that interact with private keys such as sending or signing \n" 198 "will require the passphrase to be set prior the making these calls.\n" 199 "Use the walletpassphrase call for this, and then walletlock call.\n" 200 "If the wallet is already encrypted, use the walletpassphrasechange call.\n",
206 "\nEncrypt your wallet\n" 208 "\nNow set the passphrase to use the wallet, such as for signing or sending bitcoin\n" 210 "\nNow we can do something like sign\n" 212 "\nNow lock the wallet again by removing the passphrase\n" 214 "\nAs a JSON-RPC call\n" 222 LOCK(pwallet->cs_wallet);
228 if (pwallet->IsCrypted()) {
235 strWalletPass.reserve(100);
236 strWalletPass = request.params[0].get_str().c_str();
238 if (strWalletPass.empty()) {
242 if (!pwallet->EncryptWallet(strWalletPass)) {
246 return "wallet encrypted; The keypool has been flushed and a new HD seed was generated (if you are using HD). You need to make a new backup.";
interfaces::Chain & chain() const
Interface for accessing chain state.
virtual void rpcRunLater(const std::string &name, std::function< void()> fn, int64_t seconds)=0
Run function after given number of seconds. Cancel any previous calls with same name.
RPCHelpMan walletpassphrase()
const std::string & GetName() const
Get a name for this wallet for logging/debugging purposes.
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
RecursiveMutex cs_wallet
Main wallet lock.
const std::string EXAMPLE_ADDRESS[2]
Example bech32 addresses for the RPCExamples help documentation.
Invalid, missing or duplicate parameter.
The wallet passphrase entered was incorrect.
RPCHelpMan walletpassphrasechange()
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
UniValue JSONRPCError(int code, const std::string &message)
Command given in wrong wallet encryption state (encrypting an encrypted wallet etc.)
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
bool Unlock(const CKeyingMaterial &vMasterKeyIn, bool accept_no_keys=false)
RPCHelpMan encryptwallet()
Failed to encrypt the wallet.
bool TopUpKeyPool(unsigned int kpSize=0)
#define AssertLockNotHeld(cs)
std::shared_ptr< CWallet > wallet
int64_t GetTime()
DEPRECATED, see GetTime.
std::shared_ptr< CWallet > GetWalletForJSONRPCRequest(const JSONRPCRequest &request)
Figures out what wallet, if any, to use for a JSONRPCRequest.