|
| 1 | +// SPDX-License-Identifier: CC0-1.0 |
| 2 | + |
| 3 | +use core::fmt; |
| 4 | + |
| 5 | +use bitcoin::amount::ParseAmountError; |
| 6 | +use bitcoin::hex::HexToArrayError; |
| 7 | +use internals::write_err; |
| 8 | + |
| 9 | +use crate::NumericError; |
| 10 | + |
| 11 | +/// Error when converting a `SubmitPackage` type into the model type. |
| 12 | +#[derive(Debug)] |
| 13 | +pub enum SubmitPackageError { |
| 14 | + /// Conversion of key from `tx_results` map failed. |
| 15 | + TxResultKey(HexToArrayError), |
| 16 | + /// Conversion of value from `tx_results` map failed. |
| 17 | + TxResultValue(SubmitPackageTxResultError), |
| 18 | + /// Conversion of a list item from `replaced_transactions` field failed. |
| 19 | + ReplaceTransactions(HexToArrayError), |
| 20 | +} |
| 21 | + |
| 22 | +impl fmt::Display for SubmitPackageError { |
| 23 | + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 24 | + use SubmitPackageError as E; |
| 25 | + |
| 26 | + match *self { |
| 27 | + E::TxResultKey(ref e) => |
| 28 | + write_err!(f, "conversion of key from `tx_results` map failed"; e), |
| 29 | + E::TxResultValue(ref e) => |
| 30 | + write_err!(f, "conversion of value from `tx_results` map failed"; e), |
| 31 | + E::ReplaceTransactions(ref e) => |
| 32 | + write_err!(f, "conversion of a list item from `replaced_transactions` field failed"; e), |
| 33 | + } |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +impl std::error::Error for SubmitPackageError { |
| 38 | + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { |
| 39 | + use SubmitPackageError as E; |
| 40 | + |
| 41 | + match *self { |
| 42 | + E::TxResultKey(ref e) => Some(e), |
| 43 | + E::TxResultValue(ref e) => Some(e), |
| 44 | + E::ReplaceTransactions(ref e) => Some(e), |
| 45 | + } |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +/// Error when converting a `SubmitPackageTxResult` type into the model type. |
| 50 | +#[derive(Debug)] |
| 51 | +pub enum SubmitPackageTxResultError { |
| 52 | + /// Conversion of numeric type to expected type failed. |
| 53 | + Numeric(NumericError), |
| 54 | + /// Conversion of the `txid` field failed. |
| 55 | + Txid(HexToArrayError), |
| 56 | + /// Conversion of the `other_wtxid` field failed. |
| 57 | + OtherWtxid(HexToArrayError), |
| 58 | + /// Conversion of the `fees` field failed. |
| 59 | + Fees(SubmitPackageTxResultFeesError), |
| 60 | +} |
| 61 | + |
| 62 | +impl fmt::Display for SubmitPackageTxResultError { |
| 63 | + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 64 | + use SubmitPackageTxResultError as E; |
| 65 | + |
| 66 | + match *self { |
| 67 | + E::Numeric(ref e) => write_err!(f, "numeric"; e), |
| 68 | + E::Txid(ref e) => write_err!(f, "conversion of the `txid` field failed"; e), |
| 69 | + E::OtherWtxid(ref e) => |
| 70 | + write_err!(f, "conversion of the `other_wtxid` field failed"; e), |
| 71 | + E::Fees(ref e) => write_err!(f, "conversion of the `fees` field failed"; e), |
| 72 | + } |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +impl std::error::Error for SubmitPackageTxResultError { |
| 77 | + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { |
| 78 | + use SubmitPackageTxResultError as E; |
| 79 | + |
| 80 | + match *self { |
| 81 | + E::Numeric(ref e) => Some(e), |
| 82 | + E::Txid(ref e) => Some(e), |
| 83 | + E::OtherWtxid(ref e) => Some(e), |
| 84 | + E::Fees(ref e) => Some(e), |
| 85 | + } |
| 86 | + } |
| 87 | +} |
| 88 | + |
| 89 | +impl From<NumericError> for SubmitPackageTxResultError { |
| 90 | + fn from(e: NumericError) -> Self { Self::Numeric(e) } |
| 91 | +} |
| 92 | + |
| 93 | +/// Error when converting a `SubmitPackageTxResultFees` type into the model type. |
| 94 | +#[derive(Debug)] |
| 95 | +pub enum SubmitPackageTxResultFeesError { |
| 96 | + /// Conversion of the `base_fee` field failed. |
| 97 | + BaseFee(ParseAmountError), |
| 98 | + /// Conversion of the `effective_fee_rate` field failed. |
| 99 | + EffectiveFeeRate(ParseAmountError), |
| 100 | + /// Conversion of a list item from `effective_includes` field failed. |
| 101 | + EffectiveIncludes(HexToArrayError), |
| 102 | +} |
| 103 | + |
| 104 | +impl fmt::Display for SubmitPackageTxResultFeesError { |
| 105 | + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 106 | + use SubmitPackageTxResultFeesError as E; |
| 107 | + |
| 108 | + match *self { |
| 109 | + E::BaseFee(ref e) => write_err!(f, "conversion of the `base_fee` field failed"; e), |
| 110 | + E::EffectiveFeeRate(ref e) => |
| 111 | + write_err!(f, "conversion of the `effective_fee_rate` field failed"; e), |
| 112 | + E::EffectiveIncludes(ref e) => write_err!(f, "effective_includes"; e), |
| 113 | + } |
| 114 | + } |
| 115 | +} |
| 116 | + |
| 117 | +impl std::error::Error for SubmitPackageTxResultFeesError { |
| 118 | + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { |
| 119 | + use SubmitPackageTxResultFeesError as E; |
| 120 | + |
| 121 | + match *self { |
| 122 | + E::BaseFee(ref e) => Some(e), |
| 123 | + E::EffectiveFeeRate(ref e) => Some(e), |
| 124 | + E::EffectiveIncludes(ref e) => Some(e), |
| 125 | + } |
| 126 | + } |
| 127 | +} |
0 commit comments