Merge rust-bitcoin/rust-bitcoin#1235: Correctly handle bicoinconsensus::Error
a013847bd3
Correctly handle bicoinconsensus::Error (Tobin C. Harding) Pull request description: 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. ACKs for top commit: Kixunil: ACKa013847bd3
apoelstra: ACKa013847bd3
Tree-SHA512: d9ea4ce0b01277f7c6e2f1a8b877720dba111ecfbb5de7fe5bb35bf659f5c47ee4436f021f9293717000b4cc3ccfc5dc6a893e879aca4db12bb7570be8ccaee0
This commit is contained in:
commit
1d8d04dd59
|
@ -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