MCPcopy Create free account
hub / github.com/ElementsProject/elements / walletpassphrasechange

Function walletpassphrasechange

src/wallet/rpc/encrypt.cpp:107–152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

105
106
107RPCHelpMan walletpassphrasechange()
108{
109 return RPCHelpMan{"walletpassphrasechange",
110 "\nChanges the wallet passphrase from 'oldpassphrase' to 'newpassphrase'.\n",
111 {
112 {"oldpassphrase", RPCArg::Type::STR, RPCArg::Optional::NO, "The current passphrase"},
113 {"newpassphrase", RPCArg::Type::STR, RPCArg::Optional::NO, "The new passphrase"},
114 },
115 RPCResult{RPCResult::Type::NONE, "", ""},
116 RPCExamples{
117 HelpExampleCli("walletpassphrasechange", "\"old one\" \"new one\"")
118 + HelpExampleRpc("walletpassphrasechange", "\"old one\", \"new one\"")
119 },
120 [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
121{
122 std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
123 if (!pwallet) return NullUniValue;
124
125 LOCK(pwallet->cs_wallet);
126
127 if (!pwallet->IsCrypted()) {
128 throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletpassphrasechange was called.");
129 }
130
131 // TODO: get rid of these .c_str() calls by implementing SecureString::operator=(std::string)
132 // Alternately, find a way to make request.params[0] mlock()'d to begin with.
133 SecureString strOldWalletPass;
134 strOldWalletPass.reserve(100);
135 strOldWalletPass = request.params[0].get_str().c_str();
136
137 SecureString strNewWalletPass;
138 strNewWalletPass.reserve(100);
139 strNewWalletPass = request.params[1].get_str().c_str();
140
141 if (strOldWalletPass.empty() || strNewWalletPass.empty()) {
142 throw JSONRPCError(RPC_INVALID_PARAMETER, "passphrase cannot be empty");
143 }
144
145 if (!pwallet->ChangeWalletPassphrase(strOldWalletPass, strNewWalletPass)) {
146 throw JSONRPCError(RPC_WALLET_PASSPHRASE_INCORRECT, "Error: The wallet passphrase entered was incorrect.");
147 }
148
149 return NullUniValue;
150},
151 };
152}
153
154
155RPCHelpMan walletlock()

Callers

nothing calls this directly

Calls 8

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
JSONRPCErrorFunction · 0.85
IsCryptedMethod · 0.80
reserveMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected