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);
52 strWalletPass = std::string_view{request.params[0].get_str()};
55 nSleepTime = request.params[1].getInt<int64_t>();
61 constexpr int64_t MAX_SLEEP_TIME = 100000000;
62 if (nSleepTime > MAX_SLEEP_TIME) {
63 nSleepTime = MAX_SLEEP_TIME;
66 if (strWalletPass.empty()) {
70 if (!pwallet->
Unlock(strWalletPass)) {
72 if (strWalletPass.find(
'\0') == std::string::npos) {
76 "It contains a null character (ie - a zero byte). "
77 "If the passphrase was set with a version of this software prior to 25.0, "
78 "please try again with only the characters up to — but not including — "
79 "the first null character. If this is successful, please set a new "
80 "passphrase to avoid this issue in the future.");
86 pwallet->nRelockTime =
GetTime() + nSleepTime;
87 relock_time = pwallet->nRelockTime;
98 std::weak_ptr<CWallet> weak_wallet =
wallet;
100 if (auto shared_wallet = weak_wallet.lock()) {
101 LOCK2(shared_wallet->m_relock_mutex, shared_wallet->cs_wallet);
103 if (shared_wallet->nRelockTime != relock_time) return;
104 shared_wallet->Lock();
105 shared_wallet->nRelockTime = 0;
118 "\nChanges the wallet passphrase from 'oldpassphrase' to 'newpassphrase'.\n",
125 HelpExampleCli(
"walletpassphrasechange",
"\"old one\" \"new one\"")
126 +
HelpExampleRpc(
"walletpassphrasechange",
"\"old one\", \"new one\"")
133 if (!pwallet->IsCrypted()) {
137 if (pwallet->IsScanningWithPassphrase()) {
138 throw JSONRPCError(
RPC_WALLET_ERROR,
"Error: the wallet is currently being used to rescan the blockchain for related transactions. Please call `abortrescan` before changing the passphrase.");
141 LOCK2(pwallet->m_relock_mutex, pwallet->cs_wallet);
144 strOldWalletPass.reserve(100);
145 strOldWalletPass = std::string_view{request.params[0].get_str()};
148 strNewWalletPass.reserve(100);
149 strNewWalletPass = std::string_view{request.params[1].get_str()};
151 if (strOldWalletPass.empty() || strNewWalletPass.empty()) {
155 if (!pwallet->ChangeWalletPassphrase(strOldWalletPass, strNewWalletPass)) {
157 if (strOldWalletPass.find(
'\0') == std::string::npos) {
161 "It contains a null character (ie - a zero byte). "
162 "If the old passphrase was set with a version of this software prior to 25.0, "
163 "please try again with only the characters up to — but not including — "
164 "the first null character.");
177 "\nRemoves the wallet encryption key from memory, locking the wallet.\n"
178 "After calling this method, you will need to call walletpassphrase again\n"
179 "before being able to call any methods which require the wallet to be unlocked.\n",
183 "\nSet the passphrase for 2 minutes to perform a transaction\n"
185 "\nPerform a send (requires passphrase set)\n"
187 "\nClear the passphrase since we are done before 2 minutes is up\n"
189 "\nAs a JSON-RPC call\n"
197 if (!pwallet->IsCrypted()) {
201 if (pwallet->IsScanningWithPassphrase()) {
202 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.");
205 LOCK2(pwallet->m_relock_mutex, pwallet->cs_wallet);
208 pwallet->nRelockTime = 0;
219 "\nEncrypts the wallet with 'passphrase'. This is for first time encryption.\n"
220 "After this, any calls that interact with private keys such as sending or signing \n"
221 "will require the passphrase to be set prior the making these calls.\n"
222 "Use the walletpassphrase call for this, and then walletlock call.\n"
223 "If the wallet is already encrypted, use the walletpassphrasechange call.\n"
225 "For security reasons, the encryption process will generate a new HD seed, resulting\n"
226 "in the creation of a fresh set of active descriptors. Therefore, it is crucial to\n"
227 "securely back up the newly generated wallet file using the backupwallet RPC.\n",
233 "\nEncrypt your wallet\n"
235 "\nNow set the passphrase to use the wallet, such as for signing or sending bitcoin\n"
237 "\nNow we can do something like sign\n"
239 "\nNow lock the wallet again by removing the passphrase\n"
241 "\nAs a JSON-RPC call\n"
253 if (pwallet->IsCrypted()) {
257 if (pwallet->IsScanningWithPassphrase()) {
258 throw JSONRPCError(
RPC_WALLET_ERROR,
"Error: the wallet is currently being used to rescan the blockchain for related transactions. Please call `abortrescan` before encrypting the wallet.");
261 LOCK2(pwallet->m_relock_mutex, pwallet->cs_wallet);
264 strWalletPass.reserve(100);
265 strWalletPass = std::string_view{request.params[0].get_str()};
267 if (strWalletPass.empty()) {
271 if (!pwallet->EncryptWallet(strWalletPass)) {
275 return "wallet encrypted; The keypool has been flushed and a new HD seed was generated. You need to make a new backup with the backupwallet RPC.";
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.
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
interfaces::Chain & chain() const
Interface for accessing chain state.
const std::string & GetName() const
Get a name for this wallet for logging/debugging purposes.
bool Unlock(const CKeyingMaterial &vMasterKeyIn)
RecursiveMutex cs_wallet
Main wallet lock.
bool TopUpKeyPool(unsigned int kpSize=0)
std::shared_ptr< CWallet > GetWalletForJSONRPCRequest(const JSONRPCRequest &request)
Figures out what wallet, if any, to use for a JSONRPCRequest.
RPCHelpMan walletpassphrase()
RPCHelpMan walletpassphrasechange()
RPCHelpMan encryptwallet()
@ WALLET_FLAG_DISABLE_PRIVATE_KEYS
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_ERROR
Wallet errors.
@ 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)
const std::string EXAMPLE_ADDRESS[2]
Example bech32 addresses for the RPCExamples help documentation.
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.