scripted-diff: refactor: wallet: Delete IsCrypted
What changed, and why it matters
This commit is a simple code cleanup: it removes a duplicate function named IsCrypted() and replaces every use of it with an already-existing identical function named HasEncryptionKeys(). There is no change in behavior, no bug fix, and no security issue introduced or fixed.
No security action required. Treat as ordinary code hygiene; standard review and testing are sufficient.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit is a scripted refactor across seven files. It deletes the CWallet::IsCrypted() declaration and definition, which was implemented as a one-line wrapper returning HasEncryptionKeys(). All call sites (wallet model, RPC handlers, wallet tool, interfaces, and internal wallet methods) are mechanically replaced with direct calls to HasEncryptionKeys(). The VERIFY SCRIPT confirms the change is automated and behavior-preserving.
Changed components
src/wallet/wallet.hsrc/wallet/wallet.cppsrc/wallet/rpc/encrypt.cppsrc/wallet/rpc/wallet.cppsrc/wallet/interfaces.cppsrc/wallet/wallettool.cppsrc/qt/walletmodel.hInspect captured patch +15 / −21
diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h
index edecd476..c4abde8b 100644
--- a/src/qt/walletmodel.h
+++ b/src/qt/walletmodel.h
@@ -68,9 +68,9 @@ public:
enum EncryptionStatus
{
NoKeys, // wallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)
- Unencrypted, // !wallet->IsCrypted()
- Locked, // wallet->IsCrypted() && wallet->IsLocked()
- Unlocked // wallet->IsCrypted() && !wallet->IsLocked()
+ Unencrypted, // !wallet->HasEncryptionKeys()
+ Locked, // wallet->HasEncryptionKeys() && wallet->IsLocked()
+ Unlocked // wallet->HasEncryptionKeys() && !wallet->IsLocked()
};
OptionsModel* getOptionsModel() const;
diff --git a/src/wallet/interfaces.cpp b/src/wallet/interfaces.cpp
index 535a4af5..28c4d639 100644
--- a/src/wallet/interfaces.cpp
+++ b/src/wallet/interfaces.cpp
@@ -140,7 +140,7 @@ public:
{
return m_wallet->EncryptWallet(wallet_passphrase);
}
- bool isCrypted() override { return m_wallet->IsCrypted(); }
+ bool isCrypted() override { return m_wallet->HasEncryptionKeys(); }
bool lock() override { return m_wallet->Lock(); }
bool unlock(const SecureString& wallet_passphrase) override { return m_wallet->Unlock(wallet_passphrase); }
bool isLocked() override { return m_wallet->IsLocked(); }
@@ -623,7 +623,7 @@ public:
{
auto wallets{GetWallets(m_context)};
auto it = std::find_if(wallets.begin(), wallets.end(), [&](std::shared_ptr<CWallet> w){ return w->GetName() == wallet_name; });
- if (it != wallets.end()) return (*it)->IsCrypted();
+ if (it != wallets.end()) return (*it)->HasEncryptionKeys();
// Unloaded wallet, read db
DatabaseOptions options;
diff --git a/src/wallet/rpc/encrypt.cpp b/src/wallet/rpc/encrypt.cpp
index 0314090c..e2c22ad6 100644
--- a/src/wallet/rpc/encrypt.cpp
+++ b/src/wallet/rpc/encrypt.cpp
@@ -45,7 +45,7 @@ RPCHelpMan walletpassphrase()
{
LOCK(pwallet->cs_wallet);
- if (!pwallet->IsCrypted()) {
+ if (!pwallet->HasEncryptionKeys()) {
throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletpassphrase was called.");
}
@@ -134,7 +134,7 @@ RPCHelpMan walletpassphrasechange()
std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
if (!pwallet) return UniValue::VNULL;
- if (!pwallet->IsCrypted()) {
+ if (!pwallet->HasEncryptionKeys()) {
throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletpassphrasechange was called.");
}
@@ -199,7 +199,7 @@ RPCHelpMan walletlock()
std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request);
if (!pwallet) return UniValue::VNULL;
- if (!pwallet->IsCrypted()) {
+ if (!pwallet->HasEncryptionKeys()) {
throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an unencrypted wallet, but walletlock was called.");
}
@@ -256,7 +256,7 @@ RPCHelpMan encryptwallet()
throw JSONRPCError(RPC_WALLET_ENCRYPTION_FAILED, "Error: wallet does not contain private keys, nothing to encrypt.");
}
- if (pwallet->IsCrypted()) {
+ if (pwallet->HasEncryptionKeys()) {
throw JSONRPCError(RPC_WALLET_WRONG_ENC_STATE, "Error: running with an encrypted wallet, but encryptwallet was called.");
}
diff --git a/src/wallet/rpc/wallet.cpp b/src/wallet/rpc/wallet.cpp
index 8651b98d..a2901dd4 100644
--- a/src/wallet/rpc/wallet.cpp
+++ b/src/wallet/rpc/wallet.cpp
@@ -93,7 +93,7 @@ static RPCHelpMan getwalletinfo()
obj.pushKV("keypoolsize", (int64_t)kpExternalSize);
obj.pushKV("keypoolsize_hd_internal", pwallet->GetKeyPoolSize() - kpExternalSize);
- if (pwallet->IsCrypted()) {
+ if (pwallet->HasEncryptionKeys()) {
obj.pushKV("unlocked_until", pwallet->nRelockTime);
}
obj.pushKV("paytxfee", ValueFromAmount(pwallet->m_pay_tx_fee.GetFeePerK()));
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index 4becb340..ed9bb840 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -765,7 +765,7 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
// Only descriptor wallets can be encrypted
Assert(IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS));
- if (IsCrypted())
+ if (HasEncryptionKeys())
return false;
CKeyingMaterial plain_master_key;
@@ -3291,14 +3291,9 @@ bool CWallet::IsTxImmatureCoinBase(const CWalletTx& wtx) const
return GetTxBlocksToMaturity(wtx) > 0;
}
-bool CWallet::IsCrypted() const
-{
- return HasEncryptionKeys();
-}
-
bool CWallet::IsLocked() const
{
- if (!IsCrypted()) {
+ if (!HasEncryptionKeys()) {
return false;
}
LOCK(cs_wallet);
@@ -3307,7 +3302,7 @@ bool CWallet::IsLocked() const
bool CWallet::Lock()
{
- if (!IsCrypted())
+ if (!HasEncryptionKeys())
return false;
{
@@ -3521,7 +3516,7 @@ DescriptorScriptPubKeyMan& CWallet::SetupDescriptorScriptPubKeyMan(WalletBatch&
{
AssertLockHeld(cs_wallet);
auto spk_manager = std::unique_ptr<DescriptorScriptPubKeyMan>(new DescriptorScriptPubKeyMan(*this, m_keypool_size));
- if (IsCrypted()) {
+ if (HasEncryptionKeys()) {
if (IsLocked()) {
throw std::runtime_error(std::string(__func__) + ": Wallet is locked, cannot setup new descriptors");
}
diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h
index 1d463564..24d6b07d 100644
--- a/src/wallet/wallet.h
+++ b/src/wallet/wallet.h
@@ -489,7 +489,6 @@ public:
assert(NotifyUnload.empty());
}
- bool IsCrypted() const;
bool IsLocked() const override;
bool Lock();
diff --git a/src/wallet/wallettool.cpp b/src/wallet/wallettool.cpp
index 6aaf0827..3e335bc3 100644
--- a/src/wallet/wallettool.cpp
+++ b/src/wallet/wallettool.cpp
@@ -98,7 +98,7 @@ static void WalletShowInfo(CWallet* wallet_instance)
tfm::format(std::cout, "Name: %s\n", wallet_instance->GetName());
tfm::format(std::cout, "Format: %s\n", wallet_instance->GetDatabase().Format());
tfm::format(std::cout, "Descriptors: %s\n", wallet_instance->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS) ? "yes" : "no");
- tfm::format(std::cout, "Encrypted: %s\n", wallet_instance->IsCrypted() ? "yes" : "no");
+ tfm::format(std::cout, "Encrypted: %s\n", wallet_instance->HasEncryptionKeys() ? "yes" : "no");
tfm::format(std::cout, "HD (hd seed available): %s\n", wallet_instance->IsHDEnabled() ? "yes" : "no");
tfm::format(std::cout, "Keypool Size: %u\n", wallet_instance->GetKeyPoolSize());
tfm::format(std::cout, "Transactions: %zu\n", wallet_instance->mapWallet.size());
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.