diff --git a/bdk-ffi/src/bdk.udl b/bdk-ffi/src/bdk.udl index 28013ae7..895ebb8b 100644 --- a/bdk-ffi/src/bdk.udl +++ b/bdk-ffi/src/bdk.udl @@ -4,11 +4,6 @@ namespace bdk {}; // bdk crate - error module // ------------------------------------------------------------------------ -[Error] -enum Alpha3Error { - "Generic" -}; - [Error] interface Bip39Error { BadWordCount(u64 word_count); @@ -348,7 +343,7 @@ interface BumpFeeTxBuilder { BumpFeeTxBuilder enable_rbf_with_sequence(u32 nsequence); - [Throws=Alpha3Error] + [Throws=CreateTxError] Psbt finish([ByRef] Wallet wallet); }; diff --git a/bdk-ffi/src/error.rs b/bdk-ffi/src/error.rs index 7f0e1254..b58deb70 100644 --- a/bdk-ffi/src/error.rs +++ b/bdk-ffi/src/error.rs @@ -7,7 +7,7 @@ use bdk::descriptor::DescriptorError as BdkDescriptorError; use bdk::wallet::error::BuildFeeBumpError; use bdk::wallet::signer::SignerError as BdkSignerError; use bdk::wallet::tx_builder::{AddUtxoError, AllowShrinkingError}; -use bdk::wallet::{NewError, NewOrLoadError}; +use bdk::wallet::NewOrLoadError; use bdk_esplora::esplora_client::{Error as BdkEsploraError, Error}; use bdk_file_store::FileError as BdkFileError; use bdk_file_store::IterError; @@ -23,12 +23,6 @@ use bdk::bitcoin::bip32; use bdk::wallet::error::CreateTxError as BdkCreateTxError; use std::convert::TryInto; -#[derive(Debug, thiserror::Error)] -pub enum Alpha3Error { - #[error("generic error in ffi")] - Generic, -} - #[derive(Debug, thiserror::Error)] pub enum Bip32Error { #[error("Cannot derive from a hardened key")] @@ -510,6 +504,38 @@ impl From for CreateTxError { } } +impl From for CreateTxError { + fn from(error: AllowShrinkingError) -> Self { + match error { + AllowShrinkingError::MissingScriptPubKey(_script) => { + CreateTxError::ChangePolicyDescriptor + } + } + } +} + +impl From for CreateTxError { + fn from(error: BuildFeeBumpError) -> Self { + match error { + BuildFeeBumpError::UnknownUtxo(outpoint) => CreateTxError::UnknownUtxo { + outpoint: outpoint.to_string(), + }, + BuildFeeBumpError::TransactionNotFound(txid) => CreateTxError::UnknownUtxo { + outpoint: txid.to_string(), + }, + BuildFeeBumpError::TransactionConfirmed(txid) => CreateTxError::UnknownUtxo { + outpoint: txid.to_string(), + }, + BuildFeeBumpError::IrreplaceableTransaction(txid) => CreateTxError::UnknownUtxo { + outpoint: txid.to_string(), + }, + BuildFeeBumpError::FeeRateUnavailable => CreateTxError::FeeRateTooLow { + required: "unavailable".to_string(), + }, + } + } +} + impl From for DescriptorError { fn from(error: BdkDescriptorError) -> Self { match error { @@ -644,30 +670,6 @@ impl From for PersistenceError { } } -impl From for Alpha3Error { - fn from(_: AllowShrinkingError) -> Self { - Alpha3Error::Generic - } -} - -impl From for Alpha3Error { - fn from(_: BuildFeeBumpError) -> Self { - Alpha3Error::Generic - } -} - -impl From for Alpha3Error { - fn from(_: AddUtxoError) -> Self { - Alpha3Error::Generic - } -} - -impl From for Alpha3Error { - fn from(_: bdk::bitcoin::bip32::Error) -> Self { - Alpha3Error::Generic - } -} - impl From for Bip32Error { fn from(error: BdkBip32Error) -> Self { match error { @@ -696,12 +698,6 @@ impl From for Bip32Error { } } -impl From> for Alpha3Error { - fn from(_: NewError) -> Self { - Alpha3Error::Generic - } -} - impl From for CalculateFeeError { fn from(error: BdkCalculateFeeError) -> Self { match error { diff --git a/bdk-ffi/src/lib.rs b/bdk-ffi/src/lib.rs index 9c014532..7e27a783 100644 --- a/bdk-ffi/src/lib.rs +++ b/bdk-ffi/src/lib.rs @@ -15,7 +15,6 @@ use crate::bitcoin::Transaction; use crate::bitcoin::TxOut; use crate::descriptor::Descriptor; use crate::error::AddressError; -use crate::error::Alpha3Error; use crate::error::Bip32Error; use crate::error::Bip39Error; use crate::error::CalculateFeeError; diff --git a/bdk-ffi/src/wallet.rs b/bdk-ffi/src/wallet.rs index d81f1a37..6a578a7d 100644 --- a/bdk-ffi/src/wallet.rs +++ b/bdk-ffi/src/wallet.rs @@ -1,8 +1,8 @@ use crate::bitcoin::{FeeRate, OutPoint, Psbt, Script, Transaction}; use crate::descriptor::Descriptor; use crate::error::{ - Alpha3Error, CalculateFeeError, CannotConnectError, CreateTxError, PersistenceError, - SignerError, TxidParseError, WalletCreationError, + CalculateFeeError, CannotConnectError, CreateTxError, PersistenceError, SignerError, + TxidParseError, WalletCreationError, }; use crate::types::{AddressIndex, AddressInfo, Balance, CanonicalTx, LocalOutput, ScriptAmount}; @@ -582,13 +582,17 @@ impl BumpFeeTxBuilder { }) } - pub(crate) fn finish(&self, wallet: &Wallet) -> Result, Alpha3Error> { - let txid = Txid::from_str(self.txid.as_str()).map_err(|_| Alpha3Error::Generic)?; + pub(crate) fn finish(&self, wallet: &Wallet) -> Result, CreateTxError> { + let txid = Txid::from_str(self.txid.as_str()).map_err(|_| CreateTxError::UnknownUtxo { + outpoint: self.txid.clone(), + })?; let mut wallet = wallet.get_wallet(); - let mut tx_builder = wallet.build_fee_bump(txid)?; + let mut tx_builder = wallet.build_fee_bump(txid).map_err(CreateTxError::from)?; tx_builder.fee_rate(self.fee_rate.0); if let Some(allow_shrinking) = &self.allow_shrinking { - tx_builder.allow_shrinking(allow_shrinking.0.clone())?; + tx_builder + .allow_shrinking(allow_shrinking.0.clone()) + .map_err(CreateTxError::from)?; } if let Some(rbf) = &self.rbf { match *rbf { @@ -600,7 +604,7 @@ impl BumpFeeTxBuilder { } } } - let psbt: BdkPsbt = tx_builder.finish().map_err(|_| Alpha3Error::Generic)?; + let psbt: BdkPsbt = tx_builder.finish()?; Ok(Arc::new(psbt.into())) }