Merge bitcoin/bitcoin#35690: wallet: Introduce WalletError with machine-readable error code

a8223bb4e6 wallet: Introduce WalletError with machine-readable error code (pseudoramdom)

Pull request description:

  Per discussion in https://github.com/bitcoin/bitcoin/pull/35436#issuecomment-4923786884, `WalletError` is split out so that it can be reused by multiple wallet interface changes (#34861 in particular)

  ----

  Introduce a `wallet::WalletError`, a generic wallet-layer error type that contains
  - a machine-readable `WalletErrorCode` for programmatic handling
  - a translated user-facing `bilingual_str` message

  The initial enum is intentionally small. `WALLET_ERROR` is used for generic failures that callers should display to the user. The intention is to have more specific codes only when the callers can handle the condition differently.

ACKs for top commit:
  achow101:
    ACK a8223bb4e6
  davidgumberg:
    ACK a8223bb4e6
  polespinasa:
    ACK a8223bb4e6

Tree-SHA512: 15fedf96cb5c3e8167a236bfa1a4d01d94f258a22943e53330ab432ad04a31f81f2eac8749f38390b2d34156d283d3bf76f293c640724bd0b090dc494123b230
This commit is contained in:
merge-script
2026-07-13 23:06:24 +02:00

View File

@@ -15,6 +15,7 @@
#define BITCOIN_WALLET_TYPES_H
#include <policy/fees/block_policy_estimator.h>
#include <util/translation.h>
namespace wallet {
/**
@@ -42,6 +43,33 @@ struct CreatedTransactionResult
: tx(_tx), fee(_fee), fee_calc(_fee_calc), change_pos(_change_pos) {}
};
//! Machine-readable wallet error codes.
//!
//! @note Add new codes only when callers need to handle the condition
//! differently. For errors that should only be displayed to the user, use
//! WalletErrorCode::GenericError and provide the user-facing details in WalletError::message.
enum class WalletErrorCode {
//! Generic wallet error. Callers may present the accompanying message to
//! the user.
GenericError,
//! The wallet is locked and the operation requires access to private keys.
//! Callers may ask the user to unlock the wallet and retry the operation.
UnlockNeeded,
};
//! Wallet-layer error with both programmatic and user-facing information.
//!
//! Wallet methods should return a specific WalletErrorCode only when callers
//! can handle that condition differently. Otherwise, use WalletErrorCode::GenericError
//! and describe the failure in `message`.
struct WalletError {
//! Machine-readable error code for callers that need programmatic handling.
WalletErrorCode code;
//! User-facing translated error message
bilingual_str message;
};
} // namespace wallet
#endif // BITCOIN_WALLET_TYPES_H