use core::fmt;
use internals::write_err;
use super::{NumberOf512Seconds, NumberOfBlocks};
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct DisabledLockTimeError(pub(super) u32);
impl DisabledLockTimeError {
#[inline]
pub fn disabled_locktime_value(&self) -> u32 { self.0 }
}
impl fmt::Display for DisabledLockTimeError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "lock time 0x{:08x} has disable flag set", self.0)
}
}
#[cfg(feature = "std")]
impl std::error::Error for DisabledLockTimeError {}
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum IsSatisfiedByError {
Blocks(InvalidHeightError),
Time(InvalidTimeError),
}
impl fmt::Display for IsSatisfiedByError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Self::Blocks(ref e) => write_err!(f, "blocks"; e),
Self::Time(ref e) => write_err!(f, "time"; e),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for IsSatisfiedByError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match *self {
Self::Blocks(ref e) => Some(e),
Self::Time(ref e) => Some(e),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum IsSatisfiedByHeightError {
Satisfaction(InvalidHeightError),
Incompatible(NumberOf512Seconds),
}
impl fmt::Display for IsSatisfiedByHeightError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Self::Satisfaction(ref e) => write_err!(f, "satisfaction"; e),
Self::Incompatible(time) =>
write!(f, "tried to satisfy a lock-by-height locktime using seconds {}", time),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for IsSatisfiedByHeightError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match *self {
Self::Satisfaction(ref e) => Some(e),
Self::Incompatible(_) => None,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum IsSatisfiedByTimeError {
Satisfaction(InvalidTimeError),
Incompatible(NumberOfBlocks),
}
impl fmt::Display for IsSatisfiedByTimeError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Self::Satisfaction(ref e) => write_err!(f, "satisfaction"; e),
Self::Incompatible(blocks) =>
write!(f, "tried to satisfy a lock-by-time locktime using blocks {}", blocks),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for IsSatisfiedByTimeError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match *self {
Self::Satisfaction(ref e) => Some(e),
Self::Incompatible(_) => None,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TimeOverflowError {
pub(crate) seconds: u32,
}
impl fmt::Display for TimeOverflowError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"{} seconds is too large to be encoded to a 16 bit 512 second interval",
self.seconds
)
}
}
#[cfg(feature = "std")]
impl std::error::Error for TimeOverflowError {}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct InvalidHeightError {
pub(crate) chain_tip: crate::BlockHeight,
pub(crate) utxo_mined_at: crate::BlockHeight,
}
impl fmt::Display for InvalidHeightError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "is_satisfied_by arguments invalid (probably the wrong way around) chain_tip: {} utxo_mined_at: {}", self.chain_tip, self.utxo_mined_at
)
}
}
#[cfg(feature = "std")]
impl std::error::Error for InvalidHeightError {}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct InvalidTimeError {
pub(crate) chain_tip: crate::BlockMtp,
pub(crate) utxo_mined_at: crate::BlockMtp,
}
impl fmt::Display for InvalidTimeError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "is_satisfied_by arguments invalid (probably the wrong way around) chain_tip: {} utxo_mined_at: {}", self.chain_tip, self.utxo_mined_at
)
}
}
#[cfg(feature = "std")]
impl std::error::Error for InvalidTimeError {}