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",
229 "\nEncrypt your wallet\n" 231 "\nNow set the passphrase to use the wallet, such as for signing or sending bitcoin\n" 233 "\nNow we can do something like sign\n" 235 "\nNow lock the wallet again by removing the passphrase\n" 237 "\nAs a JSON-RPC call\n" 249 if (pwallet->IsCrypted()) {
253 if (pwallet->IsScanningWithPassphrase()) {
254 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.");
257 LOCK2(pwallet->m_relock_mutex, pwallet->cs_wallet);
260 strWalletPass.reserve(100);
261 strWalletPass = std::string_view{request.params[0].get_str()};
263 if (strWalletPass.empty()) {
267 if (!pwallet->EncryptWallet(strWalletPass)) {
271 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.