wallet, rpc: Use HandleWalletError in createwallet
What changed, and why it matters
This is a small code cleanup in Bitcoin Core's wallet creation RPC. It replaces a local error-handling block with an existing shared helper function, and adds one missing error code (encryption failure) to that helper. There is no direct evidence this fixes a security vulnerability; it is best characterized as a maintainability/refactoring change that incidentally makes error reporting more consistent.
No immediate action required. Review as part of normal code maintenance. If auditing, verify that HandleWalletError preserves the exact error message and code mapping previously used by createwallet, which the diff suggests it does.
Security signals we found
No security-relevant keywords in commit title or message
No bugfix, crash, or vulnerability description
Refactoring/utility-function consolidation
No changes to cryptographic operations, authentication, or network handling
No explicit vendor disclosure of security relevance
Evidence from the diff
The commit refactors createwallet() in src/wallet/rpc/wallet.cpp to call HandleWalletError() instead of inline JSONRPCError throwing. It also adds DatabaseStatus::FAILED_ENCRYPT -> RPC_WALLET_ENCRYPTION_FAILED mapping in src/wallet/rpc/util.cpp. Before this change, createwallet() used the encryption-failed code only for itself; after the change, the shared helper handles it. This is a behavior-preserving consolidation with no functional change visible to callers except possibly more consistent error codes from other wallet operations that already used HandleWalletError.
Changed components
src/wallet/rpc/util.cppsrc/wallet/rpc/wallet.cppRPC createwalletInspect captured patch +4 / −4
diff --git a/src/wallet/rpc/util.cpp b/src/wallet/rpc/util.cpp
index d68e6c65..46e7d437 100644
--- a/src/wallet/rpc/util.cpp
+++ b/src/wallet/rpc/util.cpp
@@ -145,6 +145,9 @@ void HandleWalletError(const std::shared_ptr<CWallet> wallet, DatabaseStatus& st
case DatabaseStatus::FAILED_INVALID_BACKUP_FILE:
code = RPC_INVALID_PARAMETER;
break;
+ case DatabaseStatus::FAILED_ENCRYPT:
+ code = RPC_WALLET_ENCRYPTION_FAILED;
+ break;
default: // RPC_WALLET_ERROR is returned for all other cases.
break;
}
diff --git a/src/wallet/rpc/wallet.cpp b/src/wallet/rpc/wallet.cpp
index c7c3f459..49808a8d 100644
--- a/src/wallet/rpc/wallet.cpp
+++ b/src/wallet/rpc/wallet.cpp
@@ -422,10 +422,7 @@ static RPCHelpMan createwallet()
bilingual_str error;
std::optional<bool> load_on_start = request.params[6].isNull() ? std::nullopt : std::optional<bool>(request.params[6].get_bool());
const std::shared_ptr<CWallet> wallet = CreateWallet(context, request.params[0].get_str(), load_on_start, options, status, error, warnings);
- if (!wallet) {
- RPCErrorCode code = status == DatabaseStatus::FAILED_ENCRYPT ? RPC_WALLET_ENCRYPTION_FAILED : RPC_WALLET_ERROR;
- throw JSONRPCError(code, error.original);
- }
+ HandleWalletError(wallet, status, error);
UniValue obj(UniValue::VOBJ);
obj.pushKV("name", wallet->GetName());
Why this scored 17/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.