Skip to content
Merged
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
21 changes: 9 additions & 12 deletions types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,9 @@ pub enum NumericError {

impl fmt::Display for NumericError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use NumericError::*;

match *self {
Negative{ ref field, value } => write!(f, "expected an unsigned numeric value however the value was negative (field name: {} value: {})", field, value),
Overflow { ref field, value } => write!(f, "a value larger than `u32::MAX` was unexpectedly encountered (field name: {} Value: {})", field, value),
Self::Negative{ ref field, value } => write!(f, "expected an unsigned numeric value however the value was negative (field name: {} value: {})", field, value),
Self::Overflow { ref field, value } => write!(f, "a value larger than `u32::MAX` was unexpectedly encountered (field name: {} Value: {})", field, value),
}
}
}
Expand Down Expand Up @@ -222,23 +220,22 @@ pub enum ScriptPubkeyError {

impl fmt::Display for ScriptPubkeyError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use ScriptPubkeyError::*;
match *self {
Hex(ref e) => write_err!(f, "conversion of the `hex` field failed"; e),
Address(ref e) => write_err!(f, "conversion of the `address` field failed"; e),
Addresses(ref e) => write_err!(f, "conversion of the `addresses` field failed"; e),
Self::Hex(ref e) => write_err!(f, "conversion of the `hex` field failed"; e),
Self::Address(ref e) => write_err!(f, "conversion of the `address` field failed"; e),
Self::Addresses(ref e) =>
write_err!(f, "conversion of the `addresses` field failed"; e),
}
}
}

#[cfg(feature = "std")]
impl std::error::Error for ScriptPubkeyError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
use ScriptPubkeyError::*;
match *self {
Hex(ref e) => Some(e),
Address(ref e) => Some(e),
Addresses(ref e) => Some(e),
Self::Hex(ref e) => Some(e),
Self::Address(ref e) => Some(e),
Self::Addresses(ref e) => Some(e),
}
}
}
Expand Down
81 changes: 29 additions & 52 deletions types/src/psbt/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ pub enum RawTransactionError {

impl fmt::Display for RawTransactionError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use RawTransactionError as E;

match *self {
E::Inputs(ref e) =>
Self::Inputs(ref e) =>
write_err!(f, "conversion of one of the transaction inputs failed"; e),
E::Outputs(ref e) =>
Self::Outputs(ref e) =>
write_err!(f, "conversion of one of the transaction outputs failed"; e),
}
}
Expand All @@ -32,11 +30,9 @@ impl fmt::Display for RawTransactionError {
#[cfg(feature = "std")]
impl std::error::Error for RawTransactionError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
use RawTransactionError as E;

match *self {
E::Inputs(ref e) => Some(e),
E::Outputs(ref e) => Some(e),
Self::Inputs(ref e) => Some(e),
Self::Outputs(ref e) => Some(e),
}
}
}
Expand All @@ -54,13 +50,11 @@ pub enum RawTransactionInputError {

impl fmt::Display for RawTransactionInputError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use RawTransactionInputError as E;

match *self {
E::Txid(ref e) => write_err!(f, "conversion of the input `txid` field failed"; e),
E::ScriptSig(ref e) =>
Self::Txid(ref e) => write_err!(f, "conversion of the input `txid` field failed"; e),
Self::ScriptSig(ref e) =>
write_err!(f, "conversion of the input `script_sig` field failed"; e),
E::Witness(ref e) =>
Self::Witness(ref e) =>
write_err!(f, "conversion of one of the `witness` hex strings failed"; e),
}
}
Expand All @@ -69,12 +63,10 @@ impl fmt::Display for RawTransactionInputError {
#[cfg(feature = "std")]
impl std::error::Error for RawTransactionInputError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
use RawTransactionInputError as E;

match *self {
E::Txid(ref e) => Some(e),
E::ScriptSig(ref e) => Some(e),
E::Witness(ref e) => Some(e),
Self::Txid(ref e) => Some(e),
Self::ScriptSig(ref e) => Some(e),
Self::Witness(ref e) => Some(e),
}
}
}
Expand All @@ -90,11 +82,9 @@ pub enum RawTransactionOutputError {

impl fmt::Display for RawTransactionOutputError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use RawTransactionOutputError as E;

match *self {
E::Value(ref e) => write_err!(f, "conversion of the output `value` field failed"; e),
E::ScriptPubkey(ref e) =>
Self::Value(ref e) => write_err!(f, "conversion of the output `value` field failed"; e),
Self::ScriptPubkey(ref e) =>
write_err!(f, "conversion of the output `script_pubkey` field failed"; e),
}
}
Expand All @@ -103,11 +93,9 @@ impl fmt::Display for RawTransactionOutputError {
#[cfg(feature = "std")]
impl std::error::Error for RawTransactionOutputError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
use RawTransactionOutputError as E;

match *self {
E::Value(ref e) => Some(e),
E::ScriptPubkey(ref e) => Some(e),
Self::Value(ref e) => Some(e),
Self::ScriptPubkey(ref e) => Some(e),
}
}
}
Expand All @@ -123,11 +111,9 @@ pub enum WitnessUtxoError {

impl fmt::Display for WitnessUtxoError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use WitnessUtxoError as E;

match *self {
E::Amount(ref e) => write_err!(f, "conversion of the `amount` field failed"; e),
E::ScriptPubkey(ref e) =>
Self::Amount(ref e) => write_err!(f, "conversion of the `amount` field failed"; e),
Self::ScriptPubkey(ref e) =>
write_err!(f, "conversion of the `script_pubkey` field failed"; e),
}
}
Expand All @@ -136,11 +122,9 @@ impl fmt::Display for WitnessUtxoError {
#[cfg(feature = "std")]
impl std::error::Error for WitnessUtxoError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
use WitnessUtxoError as E;

match *self {
E::Amount(ref e) => Some(e),
E::ScriptPubkey(ref e) => Some(e),
Self::Amount(ref e) => Some(e),
Self::ScriptPubkey(ref e) => Some(e),
}
}
}
Expand All @@ -156,24 +140,21 @@ pub enum PartialSignatureError {

impl fmt::Display for PartialSignatureError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use PartialSignatureError as E;

match *self {
E::PublicKey(ref e) =>
Self::PublicKey(ref e) =>
write_err!(f, "partial sigs key-value pair parse pubkey failed"; e),
E::Signature(ref e) => write_err!(f, "partial sigs key-value pair parse sig failed"; e),
Self::Signature(ref e) =>
write_err!(f, "partial sigs key-value pair parse sig failed"; e),
}
}
}

#[cfg(feature = "std")]
impl std::error::Error for PartialSignatureError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
use PartialSignatureError as E;

match *self {
E::PublicKey(ref e) => Some(e),
E::Signature(ref e) => Some(e),
Self::PublicKey(ref e) => Some(e),
Self::Signature(ref e) => Some(e),
}
}
}
Expand All @@ -191,26 +172,22 @@ pub enum Bip32DerivError {

impl fmt::Display for Bip32DerivError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use Bip32DerivError as E;

match *self {
E::Pubkey(ref e) => write_err!(f, "conversion of the pubkey failed"; e),
E::MasterFingerprint(ref e) =>
Self::Pubkey(ref e) => write_err!(f, "conversion of the pubkey failed"; e),
Self::MasterFingerprint(ref e) =>
write_err!(f, "conversion of the `master_fingerprint` field failed"; e),
E::Path(ref e) => write_err!(f, "conversion of the `path` field failed"; e),
Self::Path(ref e) => write_err!(f, "conversion of the `path` field failed"; e),
}
}
}

#[cfg(feature = "std")]
impl std::error::Error for Bip32DerivError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
use Bip32DerivError as E;

match *self {
E::Pubkey(ref e) => Some(e),
E::MasterFingerprint(ref e) => Some(e),
E::Path(ref e) => Some(e),
Self::Pubkey(ref e) => Some(e),
Self::MasterFingerprint(ref e) => Some(e),
Self::Path(ref e) => Some(e),
}
}
}
Loading