diff --git a/bdk-ffi/src/error.rs b/bdk-ffi/src/error.rs index ea7f48cd..80bec672 100644 --- a/bdk-ffi/src/error.rs +++ b/bdk-ffi/src/error.rs @@ -1082,9 +1082,11 @@ impl From for CreateTxError { BdkCreateTxError::OutputBelowDustLimit(index) => CreateTxError::OutputBelowDustLimit { index: index as u64, }, - BdkCreateTxError::CoinSelection(e) => CreateTxError::CoinSelection { - error_message: e.to_string(), - }, + BdkCreateTxError::CoinSelection(e) => { + let needed = e.needed.to_sat(); + let available = e.available.to_sat(); + CreateTxError::InsufficientFunds { needed, available } + } BdkCreateTxError::NoRecipients => CreateTxError::NoRecipients, BdkCreateTxError::Psbt(e) => CreateTxError::Psbt { error_message: e.to_string(), diff --git a/bdk-ffi/src/tests/error.rs b/bdk-ffi/src/tests/error.rs index d130696d..a232f787 100644 --- a/bdk-ffi/src/tests/error.rs +++ b/bdk-ffi/src/tests/error.rs @@ -1,8 +1,11 @@ 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::Amount; +use bdk_wallet::coin_selection::InsufficientFunds as BdkInsufficientFunds; +use bdk_wallet::error::CreateTxError as BdkCreateTxError; #[test] fn test_error_bip32() { @@ -104,6 +107,22 @@ fn test_error_cannot_connect() { assert_eq!(format!("{}", error), "cannot include height: 42"); } +#[test] +fn test_error_create_tx_insufficient_funds_conversion() { + let error = BdkCreateTxError::CoinSelection(BdkInsufficientFunds { + needed: Amount::from_sat(50_000), + available: Amount::from_sat(30_000), + }); + + match CreateTxError::from(error) { + CreateTxError::InsufficientFunds { needed, available } => { + assert_eq!(needed, 50_000); + assert_eq!(available, 30_000); + } + other => panic!("expected insufficient funds error, got {:?}", other), + } +} + #[test] fn test_error_descriptor() { let cases = vec![