Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated nightly rustfmt (2024-05-19) #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion base58/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ extern crate std;

static BASE58_CHARS: &[u8] = b"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";

use core::{fmt, iter, slice, str};
#[cfg(not(feature = "std"))]
pub use alloc::{string::String, vec::Vec};
use core::{fmt, iter, slice, str};
#[cfg(feature = "std")]
pub use std::{string::String, vec::Vec};

Expand Down
2 changes: 1 addition & 1 deletion groestlcoin/src/address/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl std::error::Error for FromScriptError {
}

impl From<witness_program::Error> for FromScriptError {
fn from(e : witness_program::Error) -> Self { Self::WitnessProgram(e) }
fn from(e: witness_program::Error) -> Self { Self::WitnessProgram(e) }
}

impl From<witness_version::TryFromError> for FromScriptError {
Expand Down
3 changes: 1 addition & 2 deletions groestlcoin/src/address/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use bech32grs::primitives::hrp::Hrp;
use hashes::{sha256, Hash, HashEngine};
use secp256k1::{Secp256k1, Verification, XOnlyPublicKey};

use self::error::P2shError;
use crate::blockdata::constants::{
MAX_SCRIPT_ELEMENT_SIZE, PUBKEY_ADDRESS_PREFIX_MAIN, PUBKEY_ADDRESS_PREFIX_TEST,
SCRIPT_ADDRESS_PREFIX_MAIN, SCRIPT_ADDRESS_PREFIX_TEST,
Expand All @@ -49,8 +50,6 @@ use crate::crypto::key::{
use crate::network::{Network, NetworkKind};
use crate::prelude::*;
use crate::taproot::TapNodeHash;

use self::error::P2shError;
#[rustfmt::skip] // Keep public re-exports separate.
#[doc(inline)]
pub use self::{
Expand Down
5 changes: 1 addition & 4 deletions groestlcoin/src/bip152.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,7 @@ mod test {
use crate::blockdata::locktime::absolute;
use crate::blockdata::transaction;
use crate::consensus::encode::{deserialize, serialize};
use crate::{
Amount, CompactTarget, OutPoint, ScriptBuf, Sequence, TxIn, TxOut, Txid,
Witness,
};
use crate::{Amount, CompactTarget, OutPoint, ScriptBuf, Sequence, TxIn, TxOut, Txid, Witness};

fn dummy_tx(nonce: &[u8]) -> Transaction {
Transaction {
Expand Down
2 changes: 1 addition & 1 deletion groestlcoin/src/bip32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use secp256k1::{Secp256k1, XOnlyPublicKey};

use crate::crypto::key::{CompressedPublicKey, Keypair, PrivateKey};
use crate::internal_macros::impl_bytes_newtype;
use crate::prelude::*;
use crate::network::NetworkKind;
use crate::prelude::*;

/// Version bytes for extended public keys on the Bitcoin network.
const VERSION_BYTES_MAINNET_PUBLIC: [u8; 4] = [0x04, 0x88, 0xB2, 0x1E];
Expand Down
19 changes: 15 additions & 4 deletions groestlcoin/src/blockdata/locktime/absolute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ use mutagen::mutate;
#[cfg(doc)]
use crate::absolute;
use crate::consensus::encode::{self, Decodable, Encodable};
use crate::error::{ParseIntError, PrefixedHexError, UnprefixedHexError, ContainsPrefixError, MissingPrefixError};
use crate::error::{
ContainsPrefixError, MissingPrefixError, ParseIntError, PrefixedHexError, UnprefixedHexError,
};
use crate::parse::{self, impl_parse_str, impl_parse_str_from_int_infallible};
use crate::prelude::*;

Expand Down Expand Up @@ -434,7 +436,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.
///
Expand Down Expand Up @@ -603,7 +607,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)
}
Expand Down Expand Up @@ -765,7 +770,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::*;
Expand Down
2 changes: 1 addition & 1 deletion groestlcoin/src/blockdata/script/owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use crate::blockdata::script::{
use crate::key::{
PubkeyHash, PublicKey, TapTweak, TweakedPublicKey, UntweakedPublicKey, WPubkeyHash,
};
use crate::taproot::TapNodeHash;
use crate::prelude::*;
use crate::taproot::TapNodeHash;

/// An owned, growable script.
///
Expand Down
4 changes: 2 additions & 2 deletions groestlcoin/src/blockdata/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ use crate::blockdata::script::{Script, ScriptBuf};
use crate::blockdata::witness::Witness;
use crate::blockdata::FeeRate;
use crate::consensus::{encode, Decodable, Encodable};
use crate::error::{PrefixedHexError, UnprefixedHexError, ContainsPrefixError, MissingPrefixError};
use crate::error::{ContainsPrefixError, MissingPrefixError, PrefixedHexError, UnprefixedHexError};
use crate::internal_macros::{impl_consensus_encoding, impl_hashencode};
use crate::parse::{self, impl_parse_str_from_int_infallible};
use crate::prelude::*;
#[cfg(doc)]
use crate::sighash::{EcdsaSighashType, TapSighashType};
use crate::prelude::*;
use crate::{Amount, SignedAmount, VarInt};

#[rustfmt::skip] // Keep public re-exports separate.
Expand Down
10 changes: 3 additions & 7 deletions groestlcoin/src/blockdata/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use io::{BufRead, Write};
use crate::consensus::encode::{Error, MAX_VEC_SIZE};
use crate::consensus::{Decodable, Encodable, WriteExt};
use crate::crypto::ecdsa;
use crate::taproot::{self, TAPROOT_ANNEX_PREFIX};
use crate::prelude::*;
use crate::taproot::{self, TAPROOT_ANNEX_PREFIX};
use crate::{Script, VarInt};

/// The Witness is the data used to unlock bitcoin since the [segwit upgrade].
Expand Down Expand Up @@ -235,11 +235,7 @@ impl Witness {
/// Creates a new empty [`Witness`].
#[inline]
pub const fn new() -> Self {
Witness {
content: Vec::new(),
witness_elements: 0,
indices_start: 0,
}
Witness { content: Vec::new(), witness_elements: 0, indices_start: 0 }
}

/// Creates a witness required to spend a P2WPKH output.
Expand Down Expand Up @@ -556,7 +552,7 @@ impl Default for Witness {

#[cfg(test)]
mod test {
use hex::{test_hex_unwrap as hex};
use hex::test_hex_unwrap as hex;

use super::*;
use crate::consensus::{deserialize, serialize};
Expand Down
1 change: 0 additions & 1 deletion groestlcoin/src/consensus/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ impl From<Network> for Params {
fn from(value: Network) -> Self { Self::new(value) }
}


impl From<&Network> for Params {
fn from(value: &Network) -> Self { Self::new(*value) }
}
Expand Down
46 changes: 23 additions & 23 deletions groestlcoin/src/crypto/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,32 +224,28 @@ pub struct SortKey(ArrayVec<u8, 65>);

impl fmt::Display for PublicKey {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.with_serialized(|bytes| {
fmt::Display::fmt(&bytes.as_hex(), f)
})
self.with_serialized(|bytes| fmt::Display::fmt(&bytes.as_hex(), f))
}
}

impl FromStr for PublicKey {
type Err = ParsePublicKeyError;
fn from_str(s: &str) -> Result<PublicKey, ParsePublicKeyError> {
match s.len() {
66 => {
PublicKey::from_slice(&<[u8; 33]>::from_hex(s).map_err(|op| {
match op {
HexToArrayError::Conversion(HexToBytesError::InvalidChar(char)) => ParsePublicKeyError::InvalidChar(char),
HexToArrayError::Conversion(HexToBytesError::OddLengthString(_)) | HexToArrayError::InvalidLength(_,_) => unreachable!("invalid length"),
}
})?).map_err(From::from)
},
130 => {
PublicKey::from_slice(&<[u8; 65]>::from_hex(s).map_err(|op| {
match op {
HexToArrayError::Conversion(HexToBytesError::InvalidChar(char)) => ParsePublicKeyError::InvalidChar(char),
HexToArrayError::Conversion(HexToBytesError::OddLengthString(_)) | HexToArrayError::InvalidLength(_,_) => unreachable!("invalid length"),
}
})?).map_err(From::from)
}
66 => PublicKey::from_slice(&<[u8; 33]>::from_hex(s).map_err(|op| match op {
HexToArrayError::Conversion(HexToBytesError::InvalidChar(char)) =>
ParsePublicKeyError::InvalidChar(char),
HexToArrayError::Conversion(HexToBytesError::OddLengthString(_))
| HexToArrayError::InvalidLength(_, _) => unreachable!("invalid length"),
})?)
.map_err(From::from),
130 => PublicKey::from_slice(&<[u8; 65]>::from_hex(s).map_err(|op| match op {
HexToArrayError::Conversion(HexToBytesError::InvalidChar(char)) =>
ParsePublicKeyError::InvalidChar(char),
HexToArrayError::Conversion(HexToBytesError::OddLengthString(_))
| HexToArrayError::InvalidLength(_, _) => unreachable!("invalid length"),
})?)
.map_err(From::from),
len => Err(ParsePublicKeyError::InvalidHexLength(len)),
}
}
Expand Down Expand Up @@ -441,7 +437,10 @@ impl PrivateKey {
pub fn to_bytes(self) -> Vec<u8> { self.inner[..].to_vec() }

/// Deserialize a private key from a slice
pub fn from_slice(data: &[u8], network: impl Into<NetworkKind>) -> Result<PrivateKey, secp256k1::Error> {
pub fn from_slice(
data: &[u8],
network: impl Into<NetworkKind>,
) -> Result<PrivateKey, secp256k1::Error> {
Ok(PrivateKey::new(secp256k1::SecretKey::from_slice(data)?, network))
}

Expand Down Expand Up @@ -954,7 +953,7 @@ impl std::error::Error for FromWifError {
use FromWifError::*;
match self {
Base58(e) => Some(e),
Secp256k1(e)=> Some(e),
Secp256k1(e) => Some(e),
}
}
}
Expand Down Expand Up @@ -986,7 +985,8 @@ impl fmt::Display for ParsePublicKeyError {
match self {
Encoding(e) => write_err!(f, "string error"; e),
InvalidChar(char) => write!(f, "hex error {}", char),
InvalidHexLength(got) => write!(f, "pubkey string should be 66 or 130 digits long, got: {}", got),
InvalidHexLength(got) =>
write!(f, "pubkey string should be 66 or 130 digits long, got: {}", got),
}
}
}
Expand Down Expand Up @@ -1023,7 +1023,7 @@ impl fmt::Display for ParseCompressedPublicKeyError {
use ParseCompressedPublicKeyError::*;
match self {
Secp256k1(e) => write_err!(f, "secp256k1 error"; e),
Hex(e) => write_err!(f, "invalid hex"; e)
Hex(e) => write_err!(f, "invalid hex"; e),
}
}
}
Expand Down
40 changes: 22 additions & 18 deletions groestlcoin/src/crypto/sighash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use io::Write;

use crate::blockdata::witness::Witness;
use crate::consensus::{encode, Encodable};
use crate::taproot::{LeafVersion, TapLeafHash, TAPROOT_ANNEX_PREFIX};
use crate::prelude::*;
use crate::taproot::{LeafVersion, TapLeafHash, TAPROOT_ANNEX_PREFIX};
use crate::{transaction, Amount, Script, ScriptBuf, Sequence, Transaction, TxIn, TxOut};

/// Used for signature hash for invalid use of SIGHASH_SINGLE.
Expand Down Expand Up @@ -607,8 +607,12 @@ impl<R: Borrow<Transaction>> SighashCache<R> {
// sha_sequences (32): the SHA256 of the serialization of all input nSequence.
if !anyone_can_pay {
self.common_cache().prevouts.consensus_encode(writer)?;
self.taproot_cache(prevouts.get_all().map_err(SigningDataError::sighash)?).amounts.consensus_encode(writer)?;
self.taproot_cache(prevouts.get_all().map_err(SigningDataError::sighash)?).script_pubkeys.consensus_encode(writer)?;
self.taproot_cache(prevouts.get_all().map_err(SigningDataError::sighash)?)
.amounts
.consensus_encode(writer)?;
self.taproot_cache(prevouts.get_all().map_err(SigningDataError::sighash)?)
.script_pubkeys
.consensus_encode(writer)?;
self.common_cache().sequences.consensus_encode(writer)?;
}

Expand Down Expand Up @@ -668,7 +672,8 @@ impl<R: Borrow<Transaction>> SighashCache<R> {
.ok_or(TaprootError::SingleMissingOutput(SingleMissingOutputError {
input_index,
outputs_length: self.tx.borrow().output.len(),
})).map_err(SigningDataError::Sighash)?
}))
.map_err(SigningDataError::Sighash)?
.consensus_encode(&mut enc)?;
let hash = sha256::Hash::from_engine(enc);
hash.consensus_encode(writer)?;
Expand Down Expand Up @@ -704,7 +709,8 @@ impl<R: Borrow<Transaction>> SighashCache<R> {
annex,
leaf_hash_code_separator,
sighash_type,
).map_err(SigningDataError::unwrap_sighash)?;
)
.map_err(SigningDataError::unwrap_sighash)?;
Ok(TapSighash::from_engine(enc))
}

Expand All @@ -723,7 +729,8 @@ impl<R: Borrow<Transaction>> SighashCache<R> {
None,
None,
sighash_type,
).map_err(SigningDataError::unwrap_sighash)?;
)
.map_err(SigningDataError::unwrap_sighash)?;
Ok(TapSighash::from_engine(enc))
}

Expand All @@ -746,7 +753,8 @@ impl<R: Borrow<Transaction>> SighashCache<R> {
None,
Some((leaf_hash.into(), 0xFFFFFFFF)),
sighash_type,
).map_err(SigningDataError::unwrap_sighash)?;
)
.map_err(SigningDataError::unwrap_sighash)?;
Ok(TapSighash::from_engine(enc))
}

Expand Down Expand Up @@ -830,7 +838,8 @@ impl<R: Borrow<Transaction>> SighashCache<R> {
&script_code,
value,
sighash_type,
).map_err(SigningDataError::unwrap_sighash)?;
)
.map_err(SigningDataError::unwrap_sighash)?;
Ok(SegwitV0Sighash::from_engine(enc))
}

Expand All @@ -849,7 +858,8 @@ impl<R: Borrow<Transaction>> SighashCache<R> {
witness_script,
value,
sighash_type,
).map_err(SigningDataError::unwrap_sighash)?;
)
.map_err(SigningDataError::unwrap_sighash)?;
Ok(SegwitV0Sighash::from_engine(enc))
}

Expand Down Expand Up @@ -1216,9 +1226,7 @@ pub enum P2wpkhError {
internals::impl_from_infallible!(P2wpkhError);

impl From<transaction::InputsIndexError> for P2wpkhError {
fn from(value: transaction::InputsIndexError) -> Self {
P2wpkhError::Sighash(value)
}
fn from(value: transaction::InputsIndexError) -> Self { P2wpkhError::Sighash(value) }
}

impl fmt::Display for P2wpkhError {
Expand Down Expand Up @@ -1401,17 +1409,13 @@ impl<E> SigningDataError<E> {
}
}

fn sighash<E2: Into<E>>(error: E2) -> Self {
Self::Sighash(error.into())
}
fn sighash<E2: Into<E>>(error: E2) -> Self { Self::Sighash(error.into()) }
}

// We cannot simultaneously impl `From<E>`. it was determined that this alternative requires less
// manual `map_err` calls.
impl<E> From<io::Error> for SigningDataError<E> {
fn from(value: io::Error) -> Self {
Self::Io(value)
}
fn from(value: io::Error) -> Self { Self::Io(value) }
}

impl<E: fmt::Display> fmt::Display for SigningDataError<E> {
Expand Down
2 changes: 1 addition & 1 deletion groestlcoin/src/crypto/taproot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use core::fmt;
use internals::write_err;
use io::Write;

use crate::prelude::*;
use crate::sighash::{InvalidSighashTypeError, TapSighashType};
use crate::taproot::serialized_signature::{self, SerializedSignature};
use crate::prelude::*;

/// A BIP340-341 serialized taproot signature with the corresponding hash type.
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
Expand Down
Loading