locktimes: run cargo fmt

This commit is contained in:
Andrew Poelstra 2024-03-20 22:15:55 +00:00
parent 7c910d5612
commit 2ff5085e70
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
4 changed files with 33 additions and 12 deletions

View File

@ -14,10 +14,10 @@ use io::{BufRead, Write};
use mutagen::mutate;
use units::parse;
use crate::consensus::encode::{self, Decodable, Encodable};
use crate::error::{PrefixedHexError, UnprefixedHexError, ContainsPrefixError, MissingPrefixError};
#[cfg(doc)]
use crate::absolute;
use crate::consensus::encode::{self, Decodable, Encodable};
use crate::error::{ContainsPrefixError, MissingPrefixError, PrefixedHexError, UnprefixedHexError};
#[rustfmt::skip] // Keep public re-exports separate.
#[doc(inline)]

View File

@ -131,7 +131,7 @@ impl LockTime {
match *self {
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 {
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 {
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 {
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
)
}
}

View File

@ -6,9 +6,9 @@ use core::fmt;
use internals::write_err;
use crate::parse::{self, ParseIntError};
#[cfg(feature = "alloc")]
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]).
///
@ -40,7 +40,9 @@ impl Height {
/// Creates a `Height` from a hex string.
///
/// 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.
///
@ -231,7 +233,8 @@ where
S: AsRef<str> + Into<String>,
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))?;
f(n).map_err(ParseError::from).map_err(Into::into)
}
@ -307,7 +310,13 @@ impl ParseError {
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 ParseError::*;

View File

@ -92,7 +92,7 @@ impl fmt::Display for Time {
pub struct TimeOverflowError {
/// Time value in seconds that overflowed.
// Private because we maintain an invariant that the `seconds` value does actually overflow.
pub(crate) seconds: u32
pub(crate) seconds: u32,
}
impl TimeOverflowError {
@ -109,7 +109,11 @@ impl TimeOverflowError {
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)
write!(
f,
"{} seconds is too large to be encoded to a 16 bit 512 second interval",
self.seconds
)
}
}