15 "Stores the wallet decryption key in memory for 'timeout' seconds.\n"
16 "This is needed prior to performing transactions related to private "
17 "keys such as sending bitcoins\n"
19 "Issuing the walletpassphrase command while the wallet is already "
20 "unlocked will set a new unlock\n"
21 "time that overrides the old one.\n",
24 "The wallet passphrase"},
26 "The time to keep the decryption key in seconds; capped at "
27 "100000000 (~3 years)."},
31 "\nUnlock the wallet for 60 seconds\n" +
33 "\nLock the wallet again (before 60 seconds)\n" +
38 std::shared_ptr<CWallet>
const wallet =
56 "Error: running with an unencrypted wallet, but "
57 "walletpassphrase was called.");
63 strWalletPass.reserve(100);
68 strWalletPass = request.params[0].get_str().c_str();
71 nSleepTime = request.params[1].getInt<int64_t>();
76 "Timeout cannot be negative.");
80 constexpr int64_t MAX_SLEEP_TIME = 100000000;
81 if (nSleepTime > MAX_SLEEP_TIME) {
82 nSleepTime = MAX_SLEEP_TIME;
85 if (strWalletPass.empty()) {
87 "passphrase can not be empty");
90 if (!pwallet->
Unlock(strWalletPass)) {
93 "Error: The wallet passphrase entered was incorrect.");
98 pwallet->nRelockTime =
GetTime() + nSleepTime;
99 relock_time = pwallet->nRelockTime;
111 std::weak_ptr<CWallet> weak_wallet =
wallet;
114 [weak_wallet, relock_time] {
115 if (auto shared_wallet = weak_wallet.lock()) {
116 LOCK(shared_wallet->cs_wallet);
119 if (shared_wallet->nRelockTime != relock_time) {
122 shared_wallet->Lock();
123 shared_wallet->nRelockTime = 0;
135 "walletpassphrasechange",
136 "Changes the wallet passphrase from 'oldpassphrase' to "
137 "'newpassphrase'.\n",
140 "The current passphrase"},
142 "The new passphrase"},
146 "\"old one\" \"new one\"") +
148 "\"old one\", \"new one\"")},
151 std::shared_ptr<CWallet>
const wallet =
163 "Error: running with an unencrypted wallet, but "
164 "walletpassphrasechange was called.");
172 strOldWalletPass.reserve(100);
173 strOldWalletPass = request.params[0].get_str().c_str();
176 strNewWalletPass.reserve(100);
177 strNewWalletPass = request.params[1].get_str().c_str();
179 if (strOldWalletPass.empty() || strNewWalletPass.empty()) {
181 "passphrase can not be empty");
188 "Error: The wallet passphrase entered was incorrect.");
199 "Removes the wallet encryption key from memory, locking the wallet.\n"
200 "After calling this method, you will need to call walletpassphrase "
202 "before being able to call any methods which require the wallet to be "
207 "\nSet the passphrase for 2 minutes to perform a transaction\n" +
209 "\nPerform a send (requires passphrase set)\n" +
211 "\"1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 1.0") +
212 "\nClear the passphrase since we are done before 2 minutes is "
218 std::shared_ptr<CWallet>
const wallet =
230 "Error: running with an unencrypted wallet, but "
231 "walletlock was called.");
235 pwallet->nRelockTime = 0;
245 "Encrypts the wallet with 'passphrase'. This is for first time "
247 "After this, any calls that interact with private keys such as sending "
249 "will require the passphrase to be set prior the making these calls.\n"
250 "Use the walletpassphrase call for this, and then walletlock call.\n"
251 "If the wallet is already encrypted, use the walletpassphrasechange "
255 "The pass phrase to encrypt the wallet with. It must be at least "
256 "1 character, but should be long."},
259 "A string with further instructions"},
261 "\nEncrypt your wallet\n" +
263 "\nNow set the passphrase to use the wallet, such as for signing "
264 "or sending bitcoin\n" +
266 "\nNow we can do something like sign\n" +
268 "\nNow lock the wallet again by removing the passphrase\n" +
273 std::shared_ptr<CWallet>
const wallet =
284 "Error: wallet does not contain private "
285 "keys, nothing to encrypt.");
291 "Error: running with an encrypted wallet, but "
292 "encryptwallet was called.");
300 strWalletPass.reserve(100);
301 strWalletPass = request.params[0].get_str().c_str();
303 if (strWalletPass.empty()) {
305 "passphrase can not be empty");
310 "Error: Failed to encrypt the wallet.");
313 return "wallet encrypted; The keypool has been flushed and a new "
315 "was generated (if you are using HD). You need to make a "
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
bool Unlock(const CKeyingMaterial &vMasterKeyIn, bool accept_no_keys=false)
interfaces::Chain & chain() const
Interface for accessing chain state.
const std::string & GetName() const
Get a name for this wallet for logging/debugging purposes.
A Span is an object that can refer to a contiguous sequence of objects.
virtual void rpcRunLater(const std::string &name, std::function< void()> fn, int64_t seconds)=0
Run function after given number of seconds.
RPCHelpMan walletpassphrasechange()
Span< const CRPCCommand > GetWalletEncryptRPCCommands()
RPCHelpMan encryptwallet()
RPCHelpMan walletpassphrase()
bool TopUpKeyPool(unsigned int kpSize=0)
bool ChangeWalletPassphrase(const SecureString &strOldWalletPassphrase, const SecureString &strNewWalletPassphrase)
bool EncryptWallet(const SecureString &strWalletPassphrase)
bool IsWalletFlagSet(uint64_t flag) const override
Check if a certain wallet flag is set.
UniValue JSONRPCError(int code, const std::string &message)
@ RPC_WALLET_WRONG_ENC_STATE
Command given in wrong wallet encryption state (encrypting an encrypted wallet etc....
@ RPC_WALLET_ENCRYPTION_FAILED
Failed to encrypt the wallet.
@ RPC_INVALID_PARAMETER
Invalid, missing or duplicate parameter.
@ RPC_WALLET_PASSPHRASE_INCORRECT
The wallet passphrase entered was incorrect.
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
std::basic_string< char, std::char_traits< char >, secure_allocator< char > > SecureString
#define AssertLockNotHeld(cs)
int64_t GetTime()
DEPRECATED Use either ClockType::now() or Now<TimePointType>() if a cast is needed.
const UniValue NullUniValue
std::shared_ptr< CWallet > GetWalletForJSONRPCRequest(const JSONRPCRequest &request)
Figures out what wallet, if any, to use for a JSONRPCRequest.
@ WALLET_FLAG_DISABLE_PRIVATE_KEYS