locktimes: run cargo fmt
This commit is contained in:
parent
7c910d5612
commit
2ff5085e70
|
@ -14,10 +14,10 @@ use io::{BufRead, Write};
|
||||||
use mutagen::mutate;
|
use mutagen::mutate;
|
||||||
use units::parse;
|
use units::parse;
|
||||||
|
|
||||||
use crate::consensus::encode::{self, Decodable, Encodable};
|
|
||||||
use crate::error::{PrefixedHexError, UnprefixedHexError, ContainsPrefixError, MissingPrefixError};
|
|
||||||
#[cfg(doc)]
|
#[cfg(doc)]
|
||||||
use crate::absolute;
|
use crate::absolute;
|
||||||
|
use crate::consensus::encode::{self, Decodable, Encodable};
|
||||||
|
use crate::error::{ContainsPrefixError, MissingPrefixError, PrefixedHexError, UnprefixedHexError};
|
||||||
|
|
||||||
#[rustfmt::skip] // Keep public re-exports separate.
|
#[rustfmt::skip] // Keep public re-exports separate.
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
|
|
|
@ -131,7 +131,7 @@ impl LockTime {
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
Blocks(ref h) => Ok(h.value() <= height.value()),
|
Blocks(ref h) => Ok(h.value() <= height.value()),
|
||||||
Time(time) => Err(IncompatibleHeightError { height, time })
|
Time(time) => Err(IncompatibleHeightError { height, time }),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,7 +158,7 @@ impl LockTime {
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
Time(ref t) => Ok(t.value() <= time.value()),
|
Time(ref t) => Ok(t.value() <= time.value()),
|
||||||
Blocks(height) => Err(IncompatibleTimeError { time, height })
|
Blocks(height) => Err(IncompatibleTimeError { time, height }),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -203,7 +203,11 @@ pub struct IncompatibleHeightError {
|
||||||
|
|
||||||
impl fmt::Display for IncompatibleHeightError {
|
impl fmt::Display for IncompatibleHeightError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "tried to satisfy a lock-by-blocktime lock {} with height: {}", self.time, self.height)
|
write!(
|
||||||
|
f,
|
||||||
|
"tried to satisfy a lock-by-blocktime lock {} with height: {}",
|
||||||
|
self.time, self.height
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,7 +226,11 @@ pub struct IncompatibleTimeError {
|
||||||
|
|
||||||
impl fmt::Display for IncompatibleTimeError {
|
impl fmt::Display for IncompatibleTimeError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "tried to satisfy a lock-by-blockheight lock {} with time: {}", self.height, self.time)
|
write!(
|
||||||
|
f,
|
||||||
|
"tried to satisfy a lock-by-blockheight lock {} with time: {}",
|
||||||
|
self.height, self.time
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,9 @@ use core::fmt;
|
||||||
|
|
||||||
use internals::write_err;
|
use internals::write_err;
|
||||||
|
|
||||||
|
use crate::parse::{self, ParseIntError};
|
||||||
#[cfg(feature = "alloc")]
|
#[cfg(feature = "alloc")]
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::parse::{self, ParseIntError};
|
|
||||||
|
|
||||||
/// The Threshold for deciding whether a lock time value is a height or a time (see [Bitcoin Core]).
|
/// The Threshold for deciding whether a lock time value is a height or a time (see [Bitcoin Core]).
|
||||||
///
|
///
|
||||||
|
@ -40,7 +40,9 @@ impl Height {
|
||||||
/// Creates a `Height` from a hex string.
|
/// Creates a `Height` from a hex string.
|
||||||
///
|
///
|
||||||
/// The input string is may or may not contain a typical hex prefix e.g., `0x`.
|
/// The input string is may or may not contain a typical hex prefix e.g., `0x`.
|
||||||
pub fn from_hex(s: &str) -> Result<Self, ParseHeightError> { parse_hex(s, Self::from_consensus) }
|
pub fn from_hex(s: &str) -> Result<Self, ParseHeightError> {
|
||||||
|
parse_hex(s, Self::from_consensus)
|
||||||
|
}
|
||||||
|
|
||||||
/// Constructs a new block height.
|
/// Constructs a new block height.
|
||||||
///
|
///
|
||||||
|
@ -231,7 +233,8 @@ where
|
||||||
S: AsRef<str> + Into<String>,
|
S: AsRef<str> + Into<String>,
|
||||||
F: FnOnce(u32) -> Result<T, ConversionError>,
|
F: FnOnce(u32) -> Result<T, ConversionError>,
|
||||||
{
|
{
|
||||||
let n = i64::from_str_radix(parse::strip_hex_prefix(s.as_ref()), 16).map_err(ParseError::invalid_int(s))?;
|
let n = i64::from_str_radix(parse::strip_hex_prefix(s.as_ref()), 16)
|
||||||
|
.map_err(ParseError::invalid_int(s))?;
|
||||||
let n = u32::try_from(n).map_err(|_| ParseError::Conversion(n))?;
|
let n = u32::try_from(n).map_err(|_| ParseError::Conversion(n))?;
|
||||||
f(n).map_err(ParseError::from).map_err(Into::into)
|
f(n).map_err(ParseError::from).map_err(Into::into)
|
||||||
}
|
}
|
||||||
|
@ -307,7 +310,13 @@ impl ParseError {
|
||||||
move |source| Self::InvalidInteger { source, input: s.into() }
|
move |source| Self::InvalidInteger { source, input: s.into() }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn display(&self, f: &mut fmt::Formatter<'_>, subject: &str, lower_bound: u32, upper_bound: u32) -> fmt::Result {
|
fn display(
|
||||||
|
&self,
|
||||||
|
f: &mut fmt::Formatter<'_>,
|
||||||
|
subject: &str,
|
||||||
|
lower_bound: u32,
|
||||||
|
upper_bound: u32,
|
||||||
|
) -> fmt::Result {
|
||||||
use core::num::IntErrorKind;
|
use core::num::IntErrorKind;
|
||||||
|
|
||||||
use ParseError::*;
|
use ParseError::*;
|
||||||
|
|
|
@ -92,7 +92,7 @@ impl fmt::Display for Time {
|
||||||
pub struct TimeOverflowError {
|
pub struct TimeOverflowError {
|
||||||
/// Time value in seconds that overflowed.
|
/// Time value in seconds that overflowed.
|
||||||
// Private because we maintain an invariant that the `seconds` value does actually overflow.
|
// Private because we maintain an invariant that the `seconds` value does actually overflow.
|
||||||
pub(crate) seconds: u32
|
pub(crate) seconds: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TimeOverflowError {
|
impl TimeOverflowError {
|
||||||
|
@ -109,7 +109,11 @@ impl TimeOverflowError {
|
||||||
|
|
||||||
impl fmt::Display for TimeOverflowError {
|
impl fmt::Display for TimeOverflowError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
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)
|
write!(
|
||||||
|
f,
|
||||||
|
"{} seconds is too large to be encoded to a 16 bit 512 second interval",
|
||||||
|
self.seconds
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue