Skip to content

Commit

Permalink
Enable formatter for "src"
Browse files Browse the repository at this point in the history
Remove the ignore for the "src" directory, this enables the formatter
for all source files in the `src/` directory.
  • Loading branch information
tcharding committed Jul 19, 2022
1 parent c4aeca7 commit 3099023
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 99 deletions.
1 change: 0 additions & 1 deletion rustfmt.toml
@@ -1,6 +1,5 @@
# Eventually this shoud be: ignore = []
ignore = [
"src",
"src/blockdata",
"src/consensus",
"src/network",
Expand Down
3 changes: 2 additions & 1 deletion src/hash_types.rs
Expand Up @@ -9,6 +9,7 @@
//! hash).
//!

#[rustfmt::skip]
macro_rules! impl_hashencode {
($hashtype:ident) => {
impl $crate::consensus::Encodable for $hashtype {
Expand All @@ -23,7 +24,7 @@ macro_rules! impl_hashencode {
Ok(Self::from_inner(<<$hashtype as $crate::hashes::Hash>::Inner>::consensus_decode(r)?))
}
}
}
};
}

// newtypes module is solely here so we can rustfmt::skip.
Expand Down
27 changes: 11 additions & 16 deletions src/internal_macros.rs
Expand Up @@ -100,11 +100,9 @@ macro_rules! impl_array_newtype {
type Output = <[$ty] as core::ops::Index<I>>::Output;

#[inline]
fn index(&self, index: I) -> &Self::Output {
&self.0[index]
}
fn index(&self, index: I) -> &Self::Output { &self.0[index] }
}
}
};
}

macro_rules! display_from_debug {
Expand All @@ -114,7 +112,7 @@ macro_rules! display_from_debug {
core::fmt::Debug::fmt(self, f)
}
}
}
};
}

#[cfg(test)]
Expand Down Expand Up @@ -352,8 +350,7 @@ macro_rules! serde_struct_human_string_impl {
/// - core::str::FromStr
/// - hashes::hex::FromHex
macro_rules! impl_bytes_newtype {
($t:ident, $len:literal) => (

($t:ident, $len:literal) => {
impl core::fmt::LowerHex for $t {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
for &ch in self.0.iter() {
Expand All @@ -378,9 +375,9 @@ macro_rules! impl_bytes_newtype {
impl $crate::hashes::hex::FromHex for $t {
fn from_byte_iter<I>(iter: I) -> Result<Self, $crate::hashes::hex::Error>
where
I: core::iter::Iterator<Item=Result<u8, $crate::hashes::hex::Error>>
+ core::iter::ExactSizeIterator
+ core::iter::DoubleEndedIterator,
I: core::iter::Iterator<Item = Result<u8, $crate::hashes::hex::Error>>
+ core::iter::ExactSizeIterator
+ core::iter::DoubleEndedIterator,
{
if iter.len() == $len {
let mut ret = [0; $len];
Expand Down Expand Up @@ -477,7 +474,7 @@ macro_rules! impl_bytes_newtype {
}
}
}
)
};
}

macro_rules! user_enum {
Expand Down Expand Up @@ -588,9 +585,7 @@ macro_rules! write_err {

/// Asserts a boolean expression at compile time.
macro_rules! const_assert {
($x:expr) => {
{
const _: [(); 0 - !$x as usize] = [];
}
};
($x:expr) => {{
const _: [(); 0 - !$x as usize] = [];
}};
}
109 changes: 48 additions & 61 deletions src/lib.rs
Expand Up @@ -29,11 +29,9 @@
//!

#![cfg_attr(all(not(feature = "std"), not(test)), no_std)]

// Experimental features we need.
#![cfg_attr(bench, feature(test))]
#![cfg_attr(docsrs, feature(doc_cfg))]

// Coding conventions
#![forbid(unsafe_code)]
#![deny(non_upper_case_globals)]
Expand All @@ -55,7 +53,8 @@ compile_error!(
know if you want 16-bit support. Note that we do NOT guarantee that we will implement it!"
);

#[cfg(bench)] extern crate test;
#[cfg(bench)]
extern crate test;

#[cfg(feature = "no-std")]
#[macro_use]
Expand All @@ -64,9 +63,10 @@ extern crate alloc;
extern crate core2;

// Re-exported dependencies.
#[macro_use] pub extern crate bitcoin_hashes as hashes;
pub extern crate secp256k1;
#[macro_use]
pub extern crate bitcoin_hashes as hashes;
pub extern crate bech32;
pub extern crate secp256k1;

#[cfg(feature = "no-std")]
extern crate hashbrown;
Expand All @@ -75,12 +75,19 @@ extern crate hashbrown;
#[cfg_attr(docsrs, doc(cfg(feature = "base64")))]
pub extern crate base64;

#[cfg(feature="bitcoinconsensus")] extern crate bitcoinconsensus;
#[cfg(feature = "serde")] #[macro_use] extern crate actual_serde as serde;
#[cfg(all(test, feature = "serde"))] extern crate serde_json;
#[cfg(all(test, feature = "serde"))] extern crate serde_test;
#[cfg(all(test, feature = "serde"))] extern crate bincode;
#[cfg(all(test, feature = "unstable"))] extern crate test;
#[cfg(feature = "bitcoinconsensus")]
extern crate bitcoinconsensus;
#[cfg(feature = "serde")]
#[macro_use]
extern crate actual_serde as serde;
#[cfg(all(test, feature = "serde"))]
extern crate bincode;
#[cfg(all(test, feature = "serde"))]
extern crate serde_json;
#[cfg(all(test, feature = "serde"))]
extern crate serde_test;
#[cfg(all(test, feature = "unstable"))]
extern crate test;

#[cfg(test)]
#[macro_use]
Expand All @@ -93,44 +100,36 @@ mod serde_utils;
#[macro_use]
pub mod network;
pub mod blockdata;
pub mod util;
pub mod consensus;
pub mod hash_types;
pub mod policy;
pub mod util;

pub use crate::hash_types::*;
pub use crate::blockdata::block::Block;
pub use crate::blockdata::block::BlockHeader;
#[cfg(feature = "std")]
use std::io;

#[cfg(not(feature = "std"))]
use core2::io;

pub use crate::blockdata::block::{Block, BlockHeader};
pub use crate::blockdata::script::Script;
pub use crate::blockdata::transaction::Transaction;
pub use crate::blockdata::transaction::TxIn;
pub use crate::blockdata::transaction::Sequence;
pub use crate::blockdata::transaction::TxOut;
pub use crate::blockdata::transaction::OutPoint;
pub use crate::blockdata::transaction::EcdsaSighashType;
#[allow(deprecated)]
pub use crate::blockdata::transaction::SigHashType;
pub use crate::blockdata::transaction::{
EcdsaSighashType, OutPoint, Sequence, Transaction, TxIn, TxOut,
};
pub use crate::blockdata::witness::Witness;
pub use crate::consensus::encode::VarInt;
pub use crate::hash_types::*;
pub use crate::network::constants::Network;
pub use crate::util::Error;
pub use crate::util::address::Address;
pub use crate::util::address::AddressType;
pub use crate::util::amount::Amount;
pub use crate::util::amount::Denomination;
pub use crate::util::amount::SignedAmount;
pub use crate::util::merkleblock::MerkleBlock;
pub use crate::util::sighash::SchnorrSighashType;

pub use crate::util::address::{Address, AddressType};
pub use crate::util::amount::{Amount, Denomination, SignedAmount};
pub use crate::util::ecdsa::{self, EcdsaSig, EcdsaSigError};
pub use crate::util::key::{KeyPair, PrivateKey, PublicKey, XOnlyPublicKey};
pub use crate::util::merkleblock::MerkleBlock;
pub use crate::util::schnorr::{self, SchnorrSig, SchnorrSigError};
pub use crate::util::key::{PrivateKey, PublicKey, XOnlyPublicKey, KeyPair};
pub use crate::util::psbt;
#[allow(deprecated)]
pub use crate::blockdata::transaction::SigHashType;

#[cfg(feature = "std")]
use std::io;
#[cfg(not(feature = "std"))]
use core2::io;
pub use crate::util::sighash::SchnorrSighashType;
pub use crate::util::{psbt, Error};

#[cfg(not(feature = "std"))]
mod io_extras {
Expand All @@ -140,20 +139,14 @@ mod io_extras {
}

/// Creates an instance of a writer which will successfully consume all data.
pub const fn sink() -> Sink {
Sink { _priv: () }
}
pub const fn sink() -> Sink { Sink { _priv: () } }

impl core2::io::Write for Sink {
#[inline]
fn write(&mut self, buf: &[u8]) -> core2::io::Result<usize> {
Ok(buf.len())
}
fn write(&mut self, buf: &[u8]) -> core2::io::Result<usize> { Ok(buf.len()) }

#[inline]
fn flush(&mut self) -> core2::io::Result<()> {
Ok(())
}
fn flush(&mut self) -> core2::io::Result<()> { Ok(()) }
}
}

Expand Down Expand Up @@ -184,32 +177,26 @@ mod prelude {
pub use std::collections::HashSet;
}

#[cfg(bench)] use bench::EmptyWrite;
#[cfg(bench)]
use bench::EmptyWrite;

#[cfg(bench)]
mod bench {
use core::fmt::Arguments;

use crate::io::{IoSlice, Result, Write};

#[derive(Default, Clone, Debug, PartialEq, Eq)]
pub struct EmptyWrite;

impl Write for EmptyWrite {
fn write(&mut self, buf: &[u8]) -> Result<usize> {
Ok(buf.len())
}
fn write(&mut self, buf: &[u8]) -> Result<usize> { Ok(buf.len()) }
fn write_vectored(&mut self, bufs: &[IoSlice]) -> Result<usize> {
Ok(bufs.iter().map(|s| s.len()).sum())
}
fn flush(&mut self) -> Result<()> {
Ok(())
}
fn flush(&mut self) -> Result<()> { Ok(()) }

fn write_all(&mut self, _: &[u8]) -> Result<()> {
Ok(())
}
fn write_fmt(&mut self, _: Arguments) -> Result<()> {
Ok(())
}
fn write_all(&mut self, _: &[u8]) -> Result<()> { Ok(()) }
fn write_fmt(&mut self, _: Arguments) -> Result<()> { Ok(()) }
}
}
3 changes: 2 additions & 1 deletion src/policy.rs
Expand Up @@ -13,9 +13,10 @@
//! These values were taken from bitcoind v0.21.1 (194b9b8792d9b0798fdb570b79fa51f1d1f5ebaf).
//!

use super::blockdata::constants::{MAX_BLOCK_SIGOPS_COST, WITNESS_SCALE_FACTOR};
use core::cmp;

use super::blockdata::constants::{MAX_BLOCK_SIGOPS_COST, WITNESS_SCALE_FACTOR};

/// Maximum weight of a transaction for it to be relayed by most nodes on the network
pub const MAX_STANDARD_TX_WEIGHT: u32 = 400_000;

Expand Down

0 comments on commit 3099023

Please sign in to comment.