feat: add bumpfee finish related error

This commit is contained in:
Matthew 2024-04-29 13:20:16 -05:00
parent 5e8271e158
commit ebaa6fda2f
No known key found for this signature in database
GPG Key ID: 8D4FCD82DD54DDD2
4 changed files with 45 additions and 51 deletions

View File

@ -4,11 +4,6 @@ namespace bdk {};
// bdk crate - error module // bdk crate - error module
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
[Error]
enum Alpha3Error {
"Generic"
};
[Error] [Error]
interface Bip39Error { interface Bip39Error {
BadWordCount(u64 word_count); BadWordCount(u64 word_count);
@ -348,7 +343,7 @@ interface BumpFeeTxBuilder {
BumpFeeTxBuilder enable_rbf_with_sequence(u32 nsequence); BumpFeeTxBuilder enable_rbf_with_sequence(u32 nsequence);
[Throws=Alpha3Error] [Throws=CreateTxError]
Psbt finish([ByRef] Wallet wallet); Psbt finish([ByRef] Wallet wallet);
}; };

View File

@ -7,7 +7,7 @@ use bdk::descriptor::DescriptorError as BdkDescriptorError;
use bdk::wallet::error::BuildFeeBumpError; use bdk::wallet::error::BuildFeeBumpError;
use bdk::wallet::signer::SignerError as BdkSignerError; use bdk::wallet::signer::SignerError as BdkSignerError;
use bdk::wallet::tx_builder::{AddUtxoError, AllowShrinkingError}; 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_esplora::esplora_client::{Error as BdkEsploraError, Error};
use bdk_file_store::FileError as BdkFileError; use bdk_file_store::FileError as BdkFileError;
use bdk_file_store::IterError; use bdk_file_store::IterError;
@ -23,12 +23,6 @@ use bdk::bitcoin::bip32;
use bdk::wallet::error::CreateTxError as BdkCreateTxError; use bdk::wallet::error::CreateTxError as BdkCreateTxError;
use std::convert::TryInto; use std::convert::TryInto;
#[derive(Debug, thiserror::Error)]
pub enum Alpha3Error {
#[error("generic error in ffi")]
Generic,
}
#[derive(Debug, thiserror::Error)] #[derive(Debug, thiserror::Error)]
pub enum Bip32Error { pub enum Bip32Error {
#[error("Cannot derive from a hardened key")] #[error("Cannot derive from a hardened key")]
@ -510,6 +504,38 @@ impl From<AddUtxoError> for CreateTxError {
} }
} }
impl From<AllowShrinkingError> for CreateTxError {
fn from(error: AllowShrinkingError) -> Self {
match error {
AllowShrinkingError::MissingScriptPubKey(_script) => {
CreateTxError::ChangePolicyDescriptor
}
}
}
}
impl From<BuildFeeBumpError> 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<BdkDescriptorError> for DescriptorError { impl From<BdkDescriptorError> for DescriptorError {
fn from(error: BdkDescriptorError) -> Self { fn from(error: BdkDescriptorError) -> Self {
match error { match error {
@ -644,30 +670,6 @@ impl From<std::io::Error> for PersistenceError {
} }
} }
impl From<AllowShrinkingError> for Alpha3Error {
fn from(_: AllowShrinkingError) -> Self {
Alpha3Error::Generic
}
}
impl From<BuildFeeBumpError> for Alpha3Error {
fn from(_: BuildFeeBumpError) -> Self {
Alpha3Error::Generic
}
}
impl From<AddUtxoError> for Alpha3Error {
fn from(_: AddUtxoError) -> Self {
Alpha3Error::Generic
}
}
impl From<bdk::bitcoin::bip32::Error> for Alpha3Error {
fn from(_: bdk::bitcoin::bip32::Error) -> Self {
Alpha3Error::Generic
}
}
impl From<BdkBip32Error> for Bip32Error { impl From<BdkBip32Error> for Bip32Error {
fn from(error: BdkBip32Error) -> Self { fn from(error: BdkBip32Error) -> Self {
match error { match error {
@ -696,12 +698,6 @@ impl From<BdkBip32Error> for Bip32Error {
} }
} }
impl From<NewError<std::io::Error>> for Alpha3Error {
fn from(_: NewError<std::io::Error>) -> Self {
Alpha3Error::Generic
}
}
impl From<BdkCalculateFeeError> for CalculateFeeError { impl From<BdkCalculateFeeError> for CalculateFeeError {
fn from(error: BdkCalculateFeeError) -> Self { fn from(error: BdkCalculateFeeError) -> Self {
match error { match error {

View File

@ -15,7 +15,6 @@ use crate::bitcoin::Transaction;
use crate::bitcoin::TxOut; use crate::bitcoin::TxOut;
use crate::descriptor::Descriptor; use crate::descriptor::Descriptor;
use crate::error::AddressError; use crate::error::AddressError;
use crate::error::Alpha3Error;
use crate::error::Bip32Error; use crate::error::Bip32Error;
use crate::error::Bip39Error; use crate::error::Bip39Error;
use crate::error::CalculateFeeError; use crate::error::CalculateFeeError;

View File

@ -1,8 +1,8 @@
use crate::bitcoin::{FeeRate, OutPoint, Psbt, Script, Transaction}; use crate::bitcoin::{FeeRate, OutPoint, Psbt, Script, Transaction};
use crate::descriptor::Descriptor; use crate::descriptor::Descriptor;
use crate::error::{ use crate::error::{
Alpha3Error, CalculateFeeError, CannotConnectError, CreateTxError, PersistenceError, CalculateFeeError, CannotConnectError, CreateTxError, PersistenceError, SignerError,
SignerError, TxidParseError, WalletCreationError, TxidParseError, WalletCreationError,
}; };
use crate::types::{AddressIndex, AddressInfo, Balance, CanonicalTx, LocalOutput, ScriptAmount}; use crate::types::{AddressIndex, AddressInfo, Balance, CanonicalTx, LocalOutput, ScriptAmount};
@ -390,13 +390,17 @@ impl BumpFeeTxBuilder {
}) })
} }
pub(crate) fn finish(&self, wallet: &Wallet) -> Result<Arc<Psbt>, Alpha3Error> { pub(crate) fn finish(&self, wallet: &Wallet) -> Result<Arc<Psbt>, CreateTxError> {
let txid = Txid::from_str(self.txid.as_str()).map_err(|_| Alpha3Error::Generic)?; 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 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); tx_builder.fee_rate(self.fee_rate.0);
if let Some(allow_shrinking) = &self.allow_shrinking { 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 { if let Some(rbf) = &self.rbf {
match *rbf { match *rbf {
@ -408,7 +412,7 @@ impl BumpFeeTxBuilder {
} }
} }
} }
let psbt: BdkPsbt = tx_builder.finish().map_err(|_| Alpha3Error::Generic)?; let psbt: BdkPsbt = tx_builder.finish()?;
Ok(Arc::new(psbt.into())) Ok(Arc::new(psbt.into()))
} }