Correctly handle bicoinconsensus::Error
With the latest release of `rust-bitcoinconsensus` the `bicoinconsensus::Error` now implements `std::error::Error`. Correctly handle `bicoinconsensus::Error` by returning `Some(e)` and using `write_err` as is standard across the code base.
This commit is contained in:
parent
556f85d993
commit
a013847bd3
|
@ -19,6 +19,8 @@ use core::convert::TryFrom;
|
|||
use core::{fmt, default::Default};
|
||||
use core::ops::Index;
|
||||
use crate::internal_macros::debug_from_display;
|
||||
#[cfg(feature = "bitcoinconsensus")]
|
||||
use crate::internal_macros::write_err;
|
||||
|
||||
#[cfg(feature = "serde")] use serde;
|
||||
|
||||
|
@ -169,16 +171,15 @@ pub enum Error {
|
|||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let str = match *self {
|
||||
Error::NonMinimalPush => "non-minimal datapush",
|
||||
Error::EarlyEndOfScript => "unexpected end of script",
|
||||
Error::NumericOverflow => "numeric overflow (number on stack larger than 4 bytes)",
|
||||
match *self {
|
||||
Error::NonMinimalPush => f.write_str("non-minimal datapush"),
|
||||
Error::EarlyEndOfScript => f.write_str("unexpected end of script"),
|
||||
Error::NumericOverflow => f.write_str("numeric overflow (number on stack larger than 4 bytes)"),
|
||||
#[cfg(feature = "bitcoinconsensus")]
|
||||
Error::BitcoinConsensus(ref _n) => "bitcoinconsensus verification failed",
|
||||
Error::UnknownSpentOutput(ref _point) => "unknown spent output Transaction::verify()",
|
||||
Error::Serialization => "can not serialize the spending transaction in Transaction::verify()",
|
||||
};
|
||||
f.write_str(str)
|
||||
Error::BitcoinConsensus(ref e) => write_err!(f, "bitcoinconsensus verification failed"; e),
|
||||
Error::UnknownSpentOutput(ref point) => write!(f, "unknown spent output: {}", point),
|
||||
Error::Serialization => f.write_str("can not serialize the spending transaction in Transaction::verify()"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -188,14 +189,14 @@ impl std::error::Error for Error {
|
|||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||
use self::Error::*;
|
||||
|
||||
match self {
|
||||
match *self {
|
||||
NonMinimalPush
|
||||
| EarlyEndOfScript
|
||||
| NumericOverflow
|
||||
| UnknownSpentOutput(_)
|
||||
| Serialization => None,
|
||||
#[cfg(feature = "bitcoinconsensus")]
|
||||
BitcoinConsensus(_) => None,
|
||||
BitcoinConsensus(ref e) => Some(e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue