Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 26 additions & 11 deletions bdk-ffi/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 },

Expand Down Expand Up @@ -1280,19 +1295,19 @@ impl From<BuildFeeBumpError> 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(),
},
}
Expand Down
54 changes: 49 additions & 5 deletions bdk-ffi/src/tests/error.rs
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -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 { .. }));
}
Loading