Skip to content

Commit 68cebe1

Browse files
committed
refactor(types): add Fee error variant to DecodePsbtError
Add Fee(ParseAmountError) variant to handle fee conversion failures. This prepares for the upcoming change from u64 to f64 for the fee field. Affected versions: v17, v23, v24, v30
1 parent 87c72e7 commit 68cebe1

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

types/src/v17/raw_transactions/error.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ pub enum DecodePsbtError {
2424
Inputs(PsbtInputError),
2525
/// Conversion of one of the PSBT outputs failed.
2626
Outputs(PsbtOutputError),
27+
/// Conversion of the `fee` field failed.
28+
Fee(ParseAmountError),
2729
}
2830

2931
impl fmt::Display for DecodePsbtError {
@@ -35,6 +37,7 @@ impl fmt::Display for DecodePsbtError {
3537
Self::Inputs(ref e) => write_err!(f, "conversion of one of the PSBT inputs failed"; e),
3638
Self::Outputs(ref e) =>
3739
write_err!(f, "conversion of one of the PSBT outputs failed"; e),
40+
Self::Fee(ref e) => write_err!(f, "conversion of the `fee` field failed"; e),
3841
}
3942
}
4043
}
@@ -47,6 +50,7 @@ impl std::error::Error for DecodePsbtError {
4750
Self::Unknown(ref e) => Some(e),
4851
Self::Inputs(ref e) => Some(e),
4952
Self::Outputs(ref e) => Some(e),
53+
Self::Fee(ref e) => Some(e),
5054
}
5155
}
5256
}

types/src/v23/raw_transactions/error.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use core::fmt;
44

5+
use bitcoin::amount::ParseAmountError;
56
use bitcoin::{address, bip32, hex, sighash};
67

78
use super::{Bip32DerivError, PartialSignatureError, RawTransactionError, WitnessUtxoError};
@@ -22,6 +23,8 @@ pub enum DecodePsbtError {
2223
Inputs(PsbtInputError),
2324
/// Conversion of one of the PSBT outputs failed.
2425
Outputs(PsbtOutputError),
26+
/// Conversion of the `fee` field failed.
27+
Fee(ParseAmountError),
2528
}
2629

2730
impl fmt::Display for DecodePsbtError {
@@ -37,6 +40,7 @@ impl fmt::Display for DecodePsbtError {
3740
Self::Inputs(ref e) => write_err!(f, "conversion of one of the PSBT inputs failed"; e),
3841
Self::Outputs(ref e) =>
3942
write_err!(f, "conversion of one of the PSBT outputs failed"; e),
43+
Self::Fee(ref e) => write_err!(f, "conversion of the `fee` field failed"; e),
4044
}
4145
}
4246
}
@@ -51,6 +55,7 @@ impl std::error::Error for DecodePsbtError {
5155
Self::Unknown(ref e) => Some(e),
5256
Self::Inputs(ref e) => Some(e),
5357
Self::Outputs(ref e) => Some(e),
58+
Self::Fee(ref e) => Some(e),
5459
}
5560
}
5661
}

types/src/v24/raw_transactions/error.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use core::fmt;
44

5+
use bitcoin::amount::ParseAmountError;
56
use bitcoin::taproot::{IncompleteBuilderError, TaprootBuilderError, TaprootError};
67
use bitcoin::{bip32, hex, secp256k1, sighash};
78

@@ -23,6 +24,8 @@ pub enum DecodePsbtError {
2324
Inputs(PsbtInputError),
2425
/// Conversion of one of the PSBT outputs failed.
2526
Outputs(PsbtOutputError),
27+
/// Conversion of the `fee` field failed.
28+
Fee(ParseAmountError),
2629
}
2730

2831
impl fmt::Display for DecodePsbtError {
@@ -38,6 +41,7 @@ impl fmt::Display for DecodePsbtError {
3841
Self::Inputs(ref e) => write_err!(f, "conversion of one of the PSBT inputs failed"; e),
3942
Self::Outputs(ref e) =>
4043
write_err!(f, "conversion of one of the PSBT outputs failed"; e),
44+
Self::Fee(ref e) => write_err!(f, "conversion of the `fee` field failed"; e),
4145
}
4246
}
4347
}
@@ -52,6 +56,7 @@ impl std::error::Error for DecodePsbtError {
5256
Self::Unknown(ref e) => Some(e),
5357
Self::Inputs(ref e) => Some(e),
5458
Self::Outputs(ref e) => Some(e),
59+
Self::Fee(ref e) => Some(e),
5560
}
5661
}
5762
}

types/src/v30/raw_transactions/error.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use core::fmt;
44

5+
use bitcoin::amount::ParseAmountError;
56
use bitcoin::taproot::{IncompleteBuilderError, TaprootBuilderError, TaprootError};
67
use bitcoin::{bip32, hex, secp256k1, sighash};
78

@@ -23,6 +24,8 @@ pub enum DecodePsbtError {
2324
Inputs(PsbtInputError),
2425
/// Conversion of one of the PSBT outputs failed.
2526
Outputs(PsbtOutputError),
27+
/// Conversion of the `fee` field failed.
28+
Fee(ParseAmountError),
2629
}
2730

2831
impl fmt::Display for DecodePsbtError {
@@ -38,6 +41,7 @@ impl fmt::Display for DecodePsbtError {
3841
Self::Inputs(ref e) => write_err!(f, "conversion of one of the PSBT inputs failed"; e),
3942
Self::Outputs(ref e) =>
4043
write_err!(f, "conversion of one of the PSBT outputs failed"; e),
44+
Self::Fee(ref e) => write_err!(f, "conversion of the `fee` field failed"; e),
4145
}
4246
}
4347
}
@@ -52,6 +56,7 @@ impl std::error::Error for DecodePsbtError {
5256
Self::Unknown(ref e) => Some(e),
5357
Self::Inputs(ref e) => Some(e),
5458
Self::Outputs(ref e) => Some(e),
59+
Self::Fee(ref e) => Some(e),
5560
}
5661
}
5762
}

0 commit comments

Comments
 (0)