From 79987e5be12400d7c7f698cd62dd73a91dee0ee3 Mon Sep 17 00:00:00 2001 From: Muawiya Abubakar Date: Tue, 17 Nov 2026 13:30:29 +0100 Subject: [PATCH] fix!: preserve fee bump failure variants Fee bump errors from `bdk_wallet` were collapsed into `UnknownUtxo` or `FeeRateTooLow`, so apps could not tell them apart. Add `TransactionNotFound`, `TransactionConfirmed`, `IrreplaceableTransaction`, `FeeRateUnavailable` and `InvalidOutputIndex` to `CreateTxError` and map each upstream case to its own variant. Fixes #1103 --- bdk-ffi/src/error.rs | 37 ++++++++++++++++++-------- bdk-ffi/src/tests/error.rs | 54 ++++++++++++++++++++++++++++++++++---- 2 files changed, 75 insertions(+), 16 deletions(-) diff --git a/bdk-ffi/src/error.rs b/bdk-ffi/src/error.rs index 2209a3f0..8de554eb 100644 --- a/bdk-ffi/src/error.rs +++ b/bdk-ffi/src/error.rs @@ -241,6 +241,21 @@ pub enum CreateTxError { #[error("reference to an unknown utxo: {outpoint}")] UnknownUtxo { outpoint: String }, + #[error("transaction not found in the internal database with txid: {txid}")] + TransactionNotFound { txid: String }, + + #[error("transaction already confirmed with txid: {txid}")] + TransactionConfirmed { txid: String }, + + #[error("transaction can't be replaced with txid: {txid}")] + IrreplaceableTransaction { txid: String }, + + #[error("fee rate unavailable")] + FeeRateUnavailable, + + #[error("a txin referenced an invalid output: {outpoint}")] + InvalidOutputIndex { outpoint: String }, + #[error("missing non-witness utxo for outpoint: {outpoint}")] MissingNonWitnessUtxo { outpoint: String }, @@ -1280,19 +1295,19 @@ impl From for CreateTxError { BuildFeeBumpError::UnknownUtxo(outpoint) => CreateTxError::UnknownUtxo { outpoint: outpoint.to_string(), }, - BuildFeeBumpError::TransactionNotFound(txid) => CreateTxError::UnknownUtxo { - outpoint: txid.to_string(), + BuildFeeBumpError::TransactionNotFound(txid) => CreateTxError::TransactionNotFound { + txid: txid.to_string(), }, - BuildFeeBumpError::TransactionConfirmed(txid) => CreateTxError::UnknownUtxo { - outpoint: txid.to_string(), + BuildFeeBumpError::TransactionConfirmed(txid) => CreateTxError::TransactionConfirmed { + txid: txid.to_string(), }, - BuildFeeBumpError::IrreplaceableTransaction(txid) => CreateTxError::UnknownUtxo { - outpoint: txid.to_string(), - }, - BuildFeeBumpError::FeeRateUnavailable => CreateTxError::FeeRateTooLow { - required: "unavailable".to_string(), - }, - BuildFeeBumpError::InvalidOutputIndex(outpoint) => CreateTxError::UnknownUtxo { + BuildFeeBumpError::IrreplaceableTransaction(txid) => { + CreateTxError::IrreplaceableTransaction { + txid: txid.to_string(), + } + } + BuildFeeBumpError::FeeRateUnavailable => CreateTxError::FeeRateUnavailable, + BuildFeeBumpError::InvalidOutputIndex(outpoint) => CreateTxError::InvalidOutputIndex { outpoint: outpoint.to_string(), }, } diff --git a/bdk-ffi/src/tests/error.rs b/bdk-ffi/src/tests/error.rs index 42fd8e4b..1bb5b88a 100644 --- a/bdk-ffi/src/tests/error.rs +++ b/bdk-ffi/src/tests/error.rs @@ -1,14 +1,15 @@ use crate::bitcoin::Psbt; use crate::error::{ - Bip32Error, Bip39Error, CannotConnectError, DescriptorError, DescriptorKeyError, ElectrumError, - EsploraError, ExtractTxError, PsbtError, PsbtParseError, RequestBuilderError, SignerError, - TransactionError, TxidParseError, + Bip32Error, Bip39Error, CannotConnectError, CreateTxError, DescriptorError, DescriptorKeyError, + ElectrumError, EsploraError, ExtractTxError, PsbtError, PsbtParseError, RequestBuilderError, + SignerError, TransactionError, TxidParseError, }; use bdk_wallet::bitcoin::{ - absolute, transaction, Amount as BdkAmount, Psbt as BdkPsbt, ScriptBuf as BdkScriptBuf, - Transaction as BdkTransaction, TxOut as BdkTxOut, + absolute, transaction, Amount as BdkAmount, OutPoint as BdkOutPoint, Psbt as BdkPsbt, + ScriptBuf as BdkScriptBuf, Transaction as BdkTransaction, TxOut as BdkTxOut, Txid as BdkTxid, }; +use bdk_wallet::error::BuildFeeBumpError; #[test] fn test_error_bip32() { @@ -673,3 +674,46 @@ fn test_error_txid_parse() { assert_eq!(error.to_string(), expected_message); } } + +#[test] +fn test_error_build_fee_bump() { + let txid: BdkTxid = "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b" + .parse() + .unwrap(); + let outpoint = BdkOutPoint { txid, vout: 7 }; + + let cases = vec![ + ( + BuildFeeBumpError::UnknownUtxo(outpoint), + format!("reference to an unknown utxo: {outpoint}"), + ), + ( + BuildFeeBumpError::TransactionNotFound(txid), + format!("transaction not found in the internal database with txid: {txid}"), + ), + ( + BuildFeeBumpError::TransactionConfirmed(txid), + format!("transaction already confirmed with txid: {txid}"), + ), + ( + BuildFeeBumpError::IrreplaceableTransaction(txid), + format!("transaction can't be replaced with txid: {txid}"), + ), + ( + BuildFeeBumpError::FeeRateUnavailable, + "fee rate unavailable".to_string(), + ), + ( + BuildFeeBumpError::InvalidOutputIndex(outpoint), + format!("a txin referenced an invalid output: {outpoint}"), + ), + ]; + + for (upstream, expected_message) in cases { + let error: CreateTxError = upstream.into(); + assert_eq!(error.to_string(), expected_message); + } + + let error: CreateTxError = BuildFeeBumpError::TransactionConfirmed(txid).into(); + assert!(matches!(error, CreateTxError::TransactionConfirmed { .. })); +}