feat: add bumpfee finish related error
This commit is contained in:
parent
5e8271e158
commit
ebaa6fda2f
@ -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);
|
||||
};
|
||||
|
||||
|
@ -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<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 {
|
||||
fn from(error: BdkDescriptorError) -> Self {
|
||||
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 {
|
||||
fn from(error: BdkBip32Error) -> Self {
|
||||
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 {
|
||||
fn from(error: BdkCalculateFeeError) -> Self {
|
||||
match error {
|
||||
|
@ -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;
|
||||
|
@ -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};
|
||||
|
||||
@ -390,13 +390,17 @@ impl BumpFeeTxBuilder {
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn finish(&self, wallet: &Wallet) -> Result<Arc<Psbt>, Alpha3Error> {
|
||||
let txid = Txid::from_str(self.txid.as_str()).map_err(|_| Alpha3Error::Generic)?;
|
||||
pub(crate) fn finish(&self, wallet: &Wallet) -> Result<Arc<Psbt>, 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 {
|
||||
@ -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()))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user