Inside Bitcoin
Opening the selected file…
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
251{252std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);253if (!pwallet) return UniValue::VNULL;255if (pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {256throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, "Error: wallet does not contain private keys, nothing to encrypt.");257}259if (pwallet->HasEncryptionKeys()) {260throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an encrypted wallet, but encryptwallet was called.");261}263if (pwallet->IsScanningWithPassphrase()) {264throw 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.");265}267LOCK2(pwallet->m_relock_mutex, pwallet->cs_wallet);269SecureString strWalletPass;270strWalletPass.reserve(100);271strWalletPass = std::string_view{request.params[0].get_str()};273if (strWalletPass.empty()) {274throw JSONRPCError(RPC_INVALID_PARAMETER, "passphrase cannot be empty");275}277if (!pwallet->EncryptWallet(strWalletPass)) {278throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, "Error: Failed to encrypt the wallet.");279}281return "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.";282},283};284}285} // namespace wallet