Enable formatter for "src"
Remove the ignore for the "src" directory, this enables the formatter for all source files in the `src/` directory.
This commit is contained in:
parent
743b197124
commit
ee9a3ec6a1
|
@ -1,6 +1,5 @@
|
|||
# Eventually this shoud be: ignore = []
|
||||
ignore = [
|
||||
"src",
|
||||
"src/blockdata",
|
||||
"src/consensus",
|
||||
"src/network",
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
//! hash).
|
||||
//!
|
||||
|
||||
#[rustfmt::skip]
|
||||
macro_rules! impl_hashencode {
|
||||
($hashtype:ident) => {
|
||||
impl $crate::consensus::Encodable for $hashtype {
|
||||
|
@ -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.
|
||||
|
|
|
@ -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 {
|
||||
|
@ -114,7 +112,7 @@ macro_rules! display_from_debug {
|
|||
core::fmt::Debug::fmt(self, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -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() {
|
||||
|
@ -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];
|
||||
|
@ -477,7 +474,7 @@ macro_rules! impl_bytes_newtype {
|
|||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! user_enum {
|
||||
|
@ -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] = [];
|
||||
}};
|
||||
}
|
||||
|
|
113
src/lib.rs
113
src/lib.rs
|
@ -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)]
|
||||
|
@ -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]
|
||||
|
@ -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;
|
||||
|
@ -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]
|
||||
|
@ -93,45 +100,37 @@ 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 use crate::hash_types::*;
|
||||
pub use crate::blockdata::block::Block;
|
||||
pub use crate::blockdata::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;
|
||||
pub use crate::blockdata::witness::Witness;
|
||||
pub use crate::consensus::encode::VarInt;
|
||||
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::ecdsa::{self, EcdsaSig, EcdsaSigError};
|
||||
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;
|
||||
pub mod util;
|
||||
|
||||
#[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;
|
||||
#[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::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::sighash::SchnorrSighashType;
|
||||
pub use crate::util::{psbt, Error};
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
mod io_extras {
|
||||
/// A writer which will move data into the void.
|
||||
|
@ -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(()) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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(()) }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -11,10 +11,11 @@ pub mod btreemap_byte_values {
|
|||
|
||||
// NOTE: This module can be exactly copied to use with HashMap.
|
||||
|
||||
use crate::prelude::*;
|
||||
use crate::hashes::hex::{FromHex, ToHex};
|
||||
use serde;
|
||||
|
||||
use crate::hashes::hex::{FromHex, ToHex};
|
||||
use crate::prelude::*;
|
||||
|
||||
pub fn serialize<S, T>(v: &BTreeMap<T, Vec<u8>>, s: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
|
@ -52,9 +53,10 @@ pub mod btreemap_byte_values {
|
|||
write!(f, "a map with hexadecimal values")
|
||||
}
|
||||
|
||||
fn visit_map<A: serde::de::MapAccess<'de>>(self, mut a: A)
|
||||
-> Result<Self::Value, A::Error>
|
||||
{
|
||||
fn visit_map<A: serde::de::MapAccess<'de>>(
|
||||
self,
|
||||
mut a: A,
|
||||
) -> Result<Self::Value, A::Error> {
|
||||
let mut ret = BTreeMap::new();
|
||||
while let Some((key, value)) = a.next_entry()? {
|
||||
ret.insert(key, FromHex::from_hex(value).map_err(serde::de::Error::custom)?);
|
||||
|
@ -79,9 +81,10 @@ pub mod btreemap_as_seq {
|
|||
|
||||
// NOTE: This module can be exactly copied to use with HashMap.
|
||||
|
||||
use crate::prelude::*;
|
||||
use serde;
|
||||
|
||||
use crate::prelude::*;
|
||||
|
||||
pub fn serialize<S, T, U>(v: &BTreeMap<T, U>, s: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
|
@ -122,9 +125,10 @@ pub mod btreemap_as_seq {
|
|||
write!(f, "a sequence of pairs")
|
||||
}
|
||||
|
||||
fn visit_seq<A: serde::de::SeqAccess<'de>>(self, mut a: A)
|
||||
-> Result<Self::Value, A::Error>
|
||||
{
|
||||
fn visit_seq<A: serde::de::SeqAccess<'de>>(
|
||||
self,
|
||||
mut a: A,
|
||||
) -> Result<Self::Value, A::Error> {
|
||||
let mut ret = BTreeMap::new();
|
||||
while let Some((key, value)) = a.next_element()? {
|
||||
ret.insert(key, value);
|
||||
|
@ -149,16 +153,16 @@ pub mod btreemap_as_seq_byte_values {
|
|||
|
||||
// NOTE: This module can be exactly copied to use with HashMap.
|
||||
|
||||
use crate::prelude::*;
|
||||
use serde;
|
||||
|
||||
use crate::prelude::*;
|
||||
|
||||
/// A custom key-value pair type that serialized the bytes as hex.
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(crate = "actual_serde")]
|
||||
struct OwnedPair<T>(
|
||||
T,
|
||||
#[serde(deserialize_with = "crate::serde_utils::hex_bytes::deserialize")]
|
||||
Vec<u8>,
|
||||
#[serde(deserialize_with = "crate::serde_utils::hex_bytes::deserialize")] Vec<u8>,
|
||||
);
|
||||
|
||||
/// A custom key-value pair type that serialized the bytes as hex.
|
||||
|
@ -166,8 +170,7 @@ pub mod btreemap_as_seq_byte_values {
|
|||
#[serde(crate = "actual_serde")]
|
||||
struct BorrowedPair<'a, T: 'static>(
|
||||
&'a T,
|
||||
#[serde(serialize_with = "crate::serde_utils::hex_bytes::serialize")]
|
||||
&'a [u8],
|
||||
#[serde(serialize_with = "crate::serde_utils::hex_bytes::serialize")] &'a [u8],
|
||||
);
|
||||
|
||||
pub fn serialize<S, T>(v: &BTreeMap<T, Vec<u8>>, s: S) -> Result<S::Ok, S::Error>
|
||||
|
@ -207,9 +210,10 @@ pub mod btreemap_as_seq_byte_values {
|
|||
write!(f, "a sequence of pairs")
|
||||
}
|
||||
|
||||
fn visit_seq<A: serde::de::SeqAccess<'de>>(self, mut a: A)
|
||||
-> Result<Self::Value, A::Error>
|
||||
{
|
||||
fn visit_seq<A: serde::de::SeqAccess<'de>>(
|
||||
self,
|
||||
mut a: A,
|
||||
) -> Result<Self::Value, A::Error> {
|
||||
let mut ret = BTreeMap::new();
|
||||
while let Option::Some(OwnedPair(key, value)) = a.next_element()? {
|
||||
ret.insert(key, value);
|
||||
|
@ -236,7 +240,8 @@ pub mod hex_bytes {
|
|||
|
||||
pub fn serialize<T, S>(bytes: &T, s: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
T: serde::Serialize + AsRef<[u8]>, S: serde::Serializer
|
||||
T: serde::Serialize + AsRef<[u8]>,
|
||||
S: serde::Serializer,
|
||||
{
|
||||
// Don't do anything special when not human readable.
|
||||
if !s.is_human_readable() {
|
||||
|
@ -248,7 +253,8 @@ pub mod hex_bytes {
|
|||
|
||||
pub fn deserialize<'de, D, B>(d: D) -> Result<B, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>, B: serde::Deserialize<'de> + FromHex,
|
||||
D: serde::Deserializer<'de>,
|
||||
B: serde::Deserialize<'de> + FromHex,
|
||||
{
|
||||
struct Visitor<B>(core::marker::PhantomData<B>);
|
||||
|
||||
|
|
Loading…
Reference in New Issue