|
2 | 2 |
|
3 | 3 | use core::fmt; |
4 | 4 |
|
5 | | -use bitcoin::amount::ParseAmountError; |
6 | 5 | use bitcoin::error::UnprefixedHexError; |
7 | | -use bitcoin::{consensus, hex}; |
8 | 6 |
|
9 | 7 | use crate::error::write_err; |
10 | | -use crate::NumericError; |
11 | | - |
12 | | -/// Error when converting a `BlockTemplateTransaction` type into the model type. |
13 | | -#[derive(Debug)] |
14 | | -pub enum BlockTemplateTransactionError { |
15 | | - /// Conversion of numeric type to expected type failed. |
16 | | - Numeric(NumericError), |
17 | | - /// Conversion of the `data` field failed. |
18 | | - Data(consensus::encode::FromHexError), |
19 | | - /// Conversion of the `txid` field failed. |
20 | | - Txid(hex::HexToArrayError), |
21 | | - /// Conversion of the `hash` field failed. |
22 | | - Hash(hex::HexToArrayError), |
23 | | - /// Conversion of the `fee` field failed. |
24 | | - Fee(ParseAmountError), |
25 | | -} |
26 | | - |
27 | | -impl fmt::Display for BlockTemplateTransactionError { |
28 | | - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
29 | | - use BlockTemplateTransactionError as E; |
30 | | - |
31 | | - match *self { |
32 | | - E::Numeric(ref e) => write_err!(f, "numeric"; e), |
33 | | - E::Data(ref e) => write_err!(f, "conversion of the `data` field failed"; e), |
34 | | - E::Txid(ref e) => write_err!(f, "conversion of the `txid` field failed"; e), |
35 | | - E::Hash(ref e) => write_err!(f, "conversion of the `hash` field failed"; e), |
36 | | - E::Fee(ref e) => write_err!(f, "conversion of the `fee` field failed"; e), |
37 | | - } |
38 | | - } |
39 | | -} |
40 | | - |
41 | | -#[cfg(feature = "std")] |
42 | | -impl std::error::Error for BlockTemplateTransactionError { |
43 | | - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { |
44 | | - use BlockTemplateTransactionError as E; |
45 | | - |
46 | | - match *self { |
47 | | - E::Numeric(ref e) => Some(e), |
48 | | - E::Data(ref e) => Some(e), |
49 | | - E::Txid(ref e) => Some(e), |
50 | | - E::Hash(ref e) => Some(e), |
51 | | - E::Fee(ref e) => Some(e), |
52 | | - } |
53 | | - } |
54 | | -} |
55 | | - |
56 | | -impl From<NumericError> for BlockTemplateTransactionError { |
57 | | - fn from(e: NumericError) -> Self { Self::Numeric(e) } |
58 | | -} |
59 | 8 |
|
60 | 9 | /// Error when converting a `GetMiningInfo` type into the model type. |
61 | 10 | #[derive(Debug)] |
|
0 commit comments