Merge rust-bitcoin/rust-bitcoin#1041: Remove extern crates
21a1cc791c
Use pub(crate) for macros instead of macro_use (Tobin C. Harding)23ee0930c7
Remove extern crate (Tobin C. Harding)da8b1b5439
Remove unused extern crate test (Tobin C. Harding)01a8cc6848
Remove extern crate bitcoin_hashes (Tobin C. Harding) Pull request description: Do some clean up of `extern crate` statements now we have edition 2018. 4 separate but very similar patches, separated to ease review. ACKs for top commit: sanket1729: utACK21a1cc791c
apoelstra: ACK21a1cc791c
Tree-SHA512: fba33ed8fd261cc756dad8dd94f186a5b38aaf20cf31c3a83ad7633e7bb60a390681c39ebfd913e9e242fffed3b502491d067250d72ebfe666b4d03e93c8b945
This commit is contained in:
commit
2256d4634c
|
@ -25,6 +25,7 @@ use crate::blockdata::transaction::Transaction;
|
||||||
use crate::blockdata::constants::{max_target, WITNESS_SCALE_FACTOR};
|
use crate::blockdata::constants::{max_target, WITNESS_SCALE_FACTOR};
|
||||||
use crate::blockdata::script;
|
use crate::blockdata::script;
|
||||||
use crate::VarInt;
|
use crate::VarInt;
|
||||||
|
use crate::internal_macros::impl_consensus_encoding;
|
||||||
|
|
||||||
/// Bitcoin block header.
|
/// Bitcoin block header.
|
||||||
///
|
///
|
||||||
|
|
|
@ -21,6 +21,7 @@ use crate::blockdata::block::{Block, BlockHeader};
|
||||||
use crate::blockdata::witness::Witness;
|
use crate::blockdata::witness::Witness;
|
||||||
use crate::network::constants::Network;
|
use crate::network::constants::Network;
|
||||||
use crate::util::uint::Uint256;
|
use crate::util::uint::Uint256;
|
||||||
|
use crate::internal_macros::{impl_array_newtype, impl_bytes_newtype};
|
||||||
|
|
||||||
/// The maximum allowable sequence number
|
/// The maximum allowable sequence number
|
||||||
pub const MAX_SEQUENCE: u32 = 0xFFFFFFFF;
|
pub const MAX_SEQUENCE: u32 = 0xFFFFFFFF;
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#[cfg(feature = "serde")] use crate::prelude::*;
|
#[cfg(feature = "serde")] use crate::prelude::*;
|
||||||
|
|
||||||
use core::{fmt, convert::From};
|
use core::{fmt, convert::From};
|
||||||
|
use crate::internal_macros::display_from_debug;
|
||||||
|
|
||||||
// Note: I am deliberately not implementing PartialOrd or Ord on the
|
// Note: I am deliberately not implementing PartialOrd or Ord on the
|
||||||
// opcode enum. If you want to check ranges of opcodes, etc.,
|
// opcode enum. If you want to check ranges of opcodes, etc.,
|
||||||
|
|
|
@ -18,6 +18,7 @@ use crate::io;
|
||||||
use core::convert::TryFrom;
|
use core::convert::TryFrom;
|
||||||
use core::{fmt, default::Default};
|
use core::{fmt, default::Default};
|
||||||
use core::ops::Index;
|
use core::ops::Index;
|
||||||
|
use crate::internal_macros::display_from_debug;
|
||||||
|
|
||||||
#[cfg(feature = "serde")] use serde;
|
#[cfg(feature = "serde")] use serde;
|
||||||
|
|
||||||
|
@ -998,7 +999,7 @@ impl<'de> serde::Deserialize<'de> for Script {
|
||||||
D: serde::Deserializer<'de>,
|
D: serde::Deserializer<'de>,
|
||||||
{
|
{
|
||||||
use core::fmt::Formatter;
|
use core::fmt::Formatter;
|
||||||
use hashes::hex::FromHex;
|
use crate::hashes::hex::FromHex;
|
||||||
|
|
||||||
if deserializer.is_human_readable() {
|
if deserializer.is_human_readable() {
|
||||||
|
|
||||||
|
@ -1092,6 +1093,7 @@ mod test {
|
||||||
use crate::blockdata::opcodes;
|
use crate::blockdata::opcodes;
|
||||||
use crate::util::key::PublicKey;
|
use crate::util::key::PublicKey;
|
||||||
use crate::util::psbt::serialize::Serialize;
|
use crate::util::psbt::serialize::Serialize;
|
||||||
|
use crate::internal_macros::hex_script;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn script() {
|
fn script() {
|
||||||
|
|
|
@ -30,6 +30,7 @@ use crate::consensus::{encode, Decodable, Encodable};
|
||||||
use crate::hash_types::{Sighash, Txid, Wtxid};
|
use crate::hash_types::{Sighash, Txid, Wtxid};
|
||||||
use crate::VarInt;
|
use crate::VarInt;
|
||||||
use crate::util::sighash::UINT256_ONE;
|
use crate::util::sighash::UINT256_ONE;
|
||||||
|
use crate::internal_macros::{impl_consensus_encoding, serde_string_impl, serde_struct_human_string_impl, write_err};
|
||||||
|
|
||||||
#[cfg(doc)]
|
#[cfg(doc)]
|
||||||
use crate::util::sighash::SchnorrSighashType;
|
use crate::util::sighash::SchnorrSighashType;
|
||||||
|
|
|
@ -281,7 +281,7 @@ impl serde::Serialize for Witness {
|
||||||
where
|
where
|
||||||
S: serde::Serializer,
|
S: serde::Serializer,
|
||||||
{
|
{
|
||||||
use hashes::hex::ToHex;
|
use crate::hashes::hex::ToHex;
|
||||||
use serde::ser::SerializeSeq;
|
use serde::ser::SerializeSeq;
|
||||||
|
|
||||||
let human_readable = serializer.is_human_readable();
|
let human_readable = serializer.is_human_readable();
|
||||||
|
@ -315,8 +315,8 @@ impl<'de> serde::Deserialize<'de> for Witness {
|
||||||
|
|
||||||
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>
|
||||||
{
|
{
|
||||||
use hashes::hex::FromHex;
|
use crate::hashes::hex::FromHex;
|
||||||
use hashes::hex::Error::*;
|
use crate::hashes::hex::Error::*;
|
||||||
use serde::de::{self, Unexpected};
|
use serde::de::{self, Unexpected};
|
||||||
|
|
||||||
let mut ret = match a.size_hint() {
|
let mut ret = match a.size_hint() {
|
||||||
|
|
|
@ -22,7 +22,7 @@ use core::{fmt, mem, u32, convert::From};
|
||||||
|
|
||||||
use crate::hashes::{sha256d, Hash, sha256};
|
use crate::hashes::{sha256d, Hash, sha256};
|
||||||
use crate::hash_types::{BlockHash, FilterHash, TxMerkleNode, FilterHeader};
|
use crate::hash_types::{BlockHash, FilterHash, TxMerkleNode, FilterHeader};
|
||||||
|
use crate::internal_macros::write_err;
|
||||||
use crate::io::{self, Cursor, Read};
|
use crate::io::{self, Cursor, Read};
|
||||||
|
|
||||||
use crate::util::endian;
|
use crate::util::endian;
|
||||||
|
@ -231,7 +231,7 @@ macro_rules! decoder_fn {
|
||||||
($name:ident, $val_type:ty, $readfn:ident, $byte_len: expr) => {
|
($name:ident, $val_type:ty, $readfn:ident, $byte_len: expr) => {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn $name(&mut self) -> Result<$val_type, Error> {
|
fn $name(&mut self) -> Result<$val_type, Error> {
|
||||||
const_assert!(::core::mem::size_of::<$val_type>() == $byte_len);
|
$crate::internal_macros::const_assert!(::core::mem::size_of::<$val_type>() == $byte_len);
|
||||||
let mut val = [0; $byte_len];
|
let mut val = [0; $byte_len];
|
||||||
self.read_exact(&mut val[..]).map_err(Error::Io)?;
|
self.read_exact(&mut val[..]).map_err(Error::Io)?;
|
||||||
Ok(endian::$readfn(&val))
|
Ok(endian::$readfn(&val))
|
||||||
|
|
|
@ -44,6 +44,7 @@ macro_rules! impl_consensus_encoding {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
pub(crate) use impl_consensus_encoding;
|
||||||
|
|
||||||
/// Implements standard array methods for a given wrapper type
|
/// Implements standard array methods for a given wrapper type
|
||||||
macro_rules! impl_array_newtype {
|
macro_rules! impl_array_newtype {
|
||||||
|
@ -104,6 +105,7 @@ macro_rules! impl_array_newtype {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
pub(crate) use impl_array_newtype;
|
||||||
|
|
||||||
macro_rules! display_from_debug {
|
macro_rules! display_from_debug {
|
||||||
($thing:ident) => {
|
($thing:ident) => {
|
||||||
|
@ -114,15 +116,22 @@ macro_rules! display_from_debug {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
pub(crate) use display_from_debug;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
macro_rules! hex_script (($s:expr) => (<$crate::Script as core::str::FromStr>::from_str($s).unwrap()));
|
macro_rules! hex_script (($s:expr) => (<$crate::Script as core::str::FromStr>::from_str($s).unwrap()));
|
||||||
|
#[cfg(test)]
|
||||||
|
pub(crate) use hex_script;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
macro_rules! hex_hash (($h:ident, $s:expr) => ($h::from_slice(&<$crate::prelude::Vec<u8> as $crate::hashes::hex::FromHex>::from_hex($s).unwrap()).unwrap()));
|
macro_rules! hex_hash (($h:ident, $s:expr) => ($h::from_slice(&<$crate::prelude::Vec<u8> as $crate::hashes::hex::FromHex>::from_hex($s).unwrap()).unwrap()));
|
||||||
|
#[cfg(test)]
|
||||||
|
pub(crate) use hex_hash;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
macro_rules! hex_decode (($h:ident, $s:expr) => (deserialize::<$h>(&<$crate::prelude::Vec<u8> as $crate::hashes::hex::FromHex>::from_hex($s).unwrap()).unwrap()));
|
macro_rules! hex_decode (($h:ident, $s:expr) => (deserialize::<$h>(&<$crate::prelude::Vec<u8> as $crate::hashes::hex::FromHex>::from_hex($s).unwrap()).unwrap()));
|
||||||
|
#[cfg(test)]
|
||||||
|
pub(crate) use hex_decode;
|
||||||
|
|
||||||
macro_rules! serde_string_impl {
|
macro_rules! serde_string_impl {
|
||||||
($name:ident, $expecting:literal) => {
|
($name:ident, $expecting:literal) => {
|
||||||
|
@ -168,6 +177,7 @@ macro_rules! serde_string_impl {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
pub(crate) use serde_string_impl;
|
||||||
|
|
||||||
/// A combination macro where the human-readable serialization is done like
|
/// A combination macro where the human-readable serialization is done like
|
||||||
/// serde_string_impl and the non-human-readable impl is done as a struct.
|
/// serde_string_impl and the non-human-readable impl is done as a struct.
|
||||||
|
@ -342,6 +352,7 @@ macro_rules! serde_struct_human_string_impl {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
pub(crate) use serde_struct_human_string_impl;
|
||||||
|
|
||||||
/// Implements several traits for byte-based newtypes.
|
/// Implements several traits for byte-based newtypes.
|
||||||
/// Implements:
|
/// Implements:
|
||||||
|
@ -476,6 +487,7 @@ macro_rules! impl_bytes_newtype {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
pub(crate) use impl_bytes_newtype;
|
||||||
|
|
||||||
macro_rules! user_enum {
|
macro_rules! user_enum {
|
||||||
(
|
(
|
||||||
|
@ -563,6 +575,7 @@ macro_rules! user_enum {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
pub(crate) use user_enum;
|
||||||
|
|
||||||
/// Formats error. If `std` feature is OFF appends error source (delimited by `: `). We do this
|
/// Formats error. If `std` feature is OFF appends error source (delimited by `: `). We do this
|
||||||
/// because `e.source()` is only available in std builds, without this macro the error source is
|
/// because `e.source()` is only available in std builds, without this macro the error source is
|
||||||
|
@ -582,6 +595,7 @@ macro_rules! write_err {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub(crate) use write_err;
|
||||||
|
|
||||||
/// Asserts a boolean expression at compile time.
|
/// Asserts a boolean expression at compile time.
|
||||||
macro_rules! const_assert {
|
macro_rules! const_assert {
|
||||||
|
@ -589,3 +603,4 @@ macro_rules! const_assert {
|
||||||
const _: [(); 0 - !$x as usize] = [];
|
const _: [(); 0 - !$x as usize] = [];
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
pub(crate) use const_assert;
|
||||||
|
|
32
src/lib.rs
32
src/lib.rs
|
@ -59,40 +59,22 @@ extern crate test;
|
||||||
#[cfg(feature = "no-std")]
|
#[cfg(feature = "no-std")]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
#[cfg(feature = "no-std")]
|
|
||||||
extern crate core2;
|
|
||||||
|
|
||||||
// Re-exported dependencies.
|
// Re-export dependencies we control.
|
||||||
#[macro_use]
|
pub use bitcoin_hashes as hashes;
|
||||||
pub extern crate bitcoin_hashes as hashes;
|
pub use secp256k1;
|
||||||
pub extern crate bech32;
|
pub use bech32;
|
||||||
pub extern crate secp256k1;
|
#[cfg(feature="bitcoinconsensus")]
|
||||||
|
pub use bitcoinconsensus;
|
||||||
|
|
||||||
#[cfg(feature = "no-std")]
|
|
||||||
extern crate hashbrown;
|
|
||||||
|
|
||||||
#[cfg(feature = "base64")]
|
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "base64")))]
|
|
||||||
pub extern crate base64;
|
|
||||||
|
|
||||||
#[cfg(feature = "bitcoinconsensus")]
|
|
||||||
extern crate bitcoinconsensus;
|
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate actual_serde as serde;
|
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)]
|
#[cfg(test)]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod test_macros;
|
mod test_macros;
|
||||||
#[macro_use]
|
|
||||||
mod internal_macros;
|
mod internal_macros;
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
mod serde_utils;
|
mod serde_utils;
|
||||||
|
|
|
@ -30,6 +30,7 @@ use core::{fmt, ops, convert::From};
|
||||||
|
|
||||||
use crate::io;
|
use crate::io;
|
||||||
use crate::consensus::encode::{self, Encodable, Decodable};
|
use crate::consensus::encode::{self, Encodable, Decodable};
|
||||||
|
use crate::internal_macros::user_enum;
|
||||||
|
|
||||||
/// Version of the protocol as appearing in network message headers
|
/// Version of the protocol as appearing in network message headers
|
||||||
/// This constant is used to signal to other peers which features you support.
|
/// This constant is used to signal to other peers which features you support.
|
||||||
|
|
|
@ -16,6 +16,7 @@ use crate::hashes::{Hash as _, sha256d};
|
||||||
use crate::network::constants;
|
use crate::network::constants;
|
||||||
use crate::consensus::encode::{self, Decodable, Encodable};
|
use crate::consensus::encode::{self, Decodable, Encodable};
|
||||||
use crate::hash_types::{BlockHash, Txid, Wtxid};
|
use crate::hash_types::{BlockHash, Txid, Wtxid};
|
||||||
|
use crate::internal_macros::impl_consensus_encoding;
|
||||||
|
|
||||||
/// An inventory item.
|
/// An inventory item.
|
||||||
#[derive(PartialEq, Eq, Clone, Debug, Copy, Hash, PartialOrd, Ord)]
|
#[derive(PartialEq, Eq, Clone, Debug, Copy, Hash, PartialOrd, Ord)]
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
use crate::consensus::encode;
|
use crate::consensus::encode;
|
||||||
use crate::consensus::{Decodable, Encodable, ReadExt};
|
use crate::consensus::{Decodable, Encodable, ReadExt};
|
||||||
|
use crate::internal_macros::impl_consensus_encoding;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
/// `filterload` message sets the current bloom filter
|
/// `filterload` message sets the current bloom filter
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
//!
|
//!
|
||||||
|
|
||||||
use crate::hash_types::{BlockHash, FilterHash, FilterHeader};
|
use crate::hash_types::{BlockHash, FilterHash, FilterHeader};
|
||||||
|
use crate::internal_macros::impl_consensus_encoding;
|
||||||
|
|
||||||
/// getcfilters message
|
/// getcfilters message
|
||||||
#[derive(PartialEq, Eq, Clone, Debug)]
|
#[derive(PartialEq, Eq, Clone, Debug)]
|
||||||
|
|
|
@ -16,6 +16,7 @@ use crate::network::constants::{self, ServiceFlags};
|
||||||
use crate::consensus::{Encodable, Decodable, ReadExt};
|
use crate::consensus::{Encodable, Decodable, ReadExt};
|
||||||
use crate::consensus::encode;
|
use crate::consensus::encode;
|
||||||
use crate::hashes::sha256d;
|
use crate::hashes::sha256d;
|
||||||
|
use crate::internal_macros::impl_consensus_encoding;
|
||||||
|
|
||||||
/// Some simple messages
|
/// Some simple messages
|
||||||
|
|
||||||
|
|
|
@ -235,7 +235,7 @@ pub mod hex_bytes {
|
||||||
//! Module for serialization of byte arrays as hex strings.
|
//! Module for serialization of byte arrays as hex strings.
|
||||||
#![allow(missing_docs)]
|
#![allow(missing_docs)]
|
||||||
|
|
||||||
use hashes::hex::{FromHex, ToHex};
|
use crate::hashes::hex::{FromHex, ToHex};
|
||||||
use serde;
|
use serde;
|
||||||
|
|
||||||
pub fn serialize<T, S>(bytes: &T, s: S) -> Result<S::Ok, S::Error>
|
pub fn serialize<T, S>(bytes: &T, s: S) -> Result<S::Ok, S::Error>
|
||||||
|
|
|
@ -41,6 +41,7 @@ use crate::util::taproot::TapBranchHash;
|
||||||
use crate::util::key::PublicKey;
|
use crate::util::key::PublicKey;
|
||||||
use crate::blockdata::script::Instruction;
|
use crate::blockdata::script::Instruction;
|
||||||
use crate::util::schnorr::{TapTweak, UntweakedPublicKey, TweakedPublicKey};
|
use crate::util::schnorr::{TapTweak, UntweakedPublicKey, TweakedPublicKey};
|
||||||
|
use crate::internal_macros::{serde_string_impl, write_err};
|
||||||
|
|
||||||
/// Address error.
|
/// Address error.
|
||||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||||
|
|
|
@ -15,6 +15,7 @@ use crate::hashes::{sha256d, Hash, hex};
|
||||||
use secp256k1;
|
use secp256k1;
|
||||||
|
|
||||||
use crate::util::{endian, key};
|
use crate::util::{endian, key};
|
||||||
|
use crate::internal_macros::write_err;
|
||||||
|
|
||||||
/// An error that might occur during base58 decoding
|
/// An error that might occur during base58 decoding
|
||||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone)]
|
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone)]
|
||||||
|
|
|
@ -186,6 +186,7 @@ mod tests {
|
||||||
use crate::util::address::Address;
|
use crate::util::address::Address;
|
||||||
use crate::util::key::PublicKey;
|
use crate::util::key::PublicKey;
|
||||||
use crate::hashes::hex::FromHex;
|
use crate::hashes::hex::FromHex;
|
||||||
|
use crate::internal_macros::{hex_hash, hex_script};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,7 @@ use crate::blockdata::transaction::OutPoint;
|
||||||
use crate::consensus::{Decodable, Encodable};
|
use crate::consensus::{Decodable, Encodable};
|
||||||
use crate::consensus::encode::VarInt;
|
use crate::consensus::encode::VarInt;
|
||||||
use crate::util::endian;
|
use crate::util::endian;
|
||||||
|
use crate::internal_macros::write_err;
|
||||||
|
|
||||||
/// Golomb encoding parameter as in BIP-158, see also https://gist.github.com/sipa/576d5f09c3b86c3b1b75598d799fc845
|
/// Golomb encoding parameter as in BIP-158, see also https://gist.github.com/sipa/576d5f09c3b86c3b1b75598d799fc845
|
||||||
const P: u8 = 19;
|
const P: u8 = 19;
|
||||||
|
|
|
@ -21,6 +21,7 @@ use secp256k1::{self, Secp256k1, XOnlyPublicKey};
|
||||||
use crate::network::constants::Network;
|
use crate::network::constants::Network;
|
||||||
use crate::util::{base58, endian, key};
|
use crate::util::{base58, endian, key};
|
||||||
use crate::util::key::{PublicKey, PrivateKey, KeyPair};
|
use crate::util::key::{PublicKey, PrivateKey, KeyPair};
|
||||||
|
use crate::internal_macros::{impl_array_newtype, impl_bytes_newtype, serde_string_impl, write_err};
|
||||||
|
|
||||||
/// A chain code
|
/// A chain code
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
|
|
|
@ -12,6 +12,7 @@ use crate::hashes::hex::{self, FromHex};
|
||||||
use crate::blockdata::transaction::NonStandardSighashType;
|
use crate::blockdata::transaction::NonStandardSighashType;
|
||||||
use secp256k1;
|
use secp256k1;
|
||||||
use crate::EcdsaSighashType;
|
use crate::EcdsaSighashType;
|
||||||
|
use crate::internal_macros::write_err;
|
||||||
|
|
||||||
/// An ECDSA signature with the corresponding hash type.
|
/// An ECDSA signature with the corresponding hash type.
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||||
|
|
|
@ -30,7 +30,7 @@ macro_rules! define_be_to_array {
|
||||||
($name: ident, $type: ty, $byte_len: expr) => {
|
($name: ident, $type: ty, $byte_len: expr) => {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn $name(val: $type) -> [u8; $byte_len] {
|
pub fn $name(val: $type) -> [u8; $byte_len] {
|
||||||
const_assert!(::core::mem::size_of::<$type>() == $byte_len);
|
$crate::internal_macros::const_assert!(::core::mem::size_of::<$type>() == $byte_len);
|
||||||
let mut res = [0; $byte_len];
|
let mut res = [0; $byte_len];
|
||||||
for i in 0..$byte_len {
|
for i in 0..$byte_len {
|
||||||
res[i] = ((val >> ($byte_len - i - 1)*8) & 0xff) as u8;
|
res[i] = ((val >> ($byte_len - i - 1)*8) & 0xff) as u8;
|
||||||
|
@ -43,7 +43,7 @@ macro_rules! define_le_to_array {
|
||||||
($name: ident, $type: ty, $byte_len: expr) => {
|
($name: ident, $type: ty, $byte_len: expr) => {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn $name(val: $type) -> [u8; $byte_len] {
|
pub fn $name(val: $type) -> [u8; $byte_len] {
|
||||||
const_assert!(::core::mem::size_of::<$type>() == $byte_len);
|
$crate::internal_macros::const_assert!(::core::mem::size_of::<$type>() == $byte_len);
|
||||||
let mut res = [0; $byte_len];
|
let mut res = [0; $byte_len];
|
||||||
for i in 0..$byte_len {
|
for i in 0..$byte_len {
|
||||||
res[i] = ((val >> i*8) & 0xff) as u8;
|
res[i] = ((val >> i*8) & 0xff) as u8;
|
||||||
|
|
|
@ -18,6 +18,7 @@ use crate::network::constants::Network;
|
||||||
use crate::hashes::{Hash, hash160, hex, hex::FromHex};
|
use crate::hashes::{Hash, hash160, hex, hex::FromHex};
|
||||||
use crate::hash_types::{PubkeyHash, WPubkeyHash};
|
use crate::hash_types::{PubkeyHash, WPubkeyHash};
|
||||||
use crate::util::base58;
|
use crate::util::base58;
|
||||||
|
use crate::internal_macros::write_err;
|
||||||
|
|
||||||
/// A key-related error.
|
/// A key-related error.
|
||||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||||
|
|
|
@ -33,6 +33,7 @@ mod message_signing {
|
||||||
|
|
||||||
use crate::util::key::PublicKey;
|
use crate::util::key::PublicKey;
|
||||||
use crate::util::address::{Address, AddressType};
|
use crate::util::address::{Address, AddressType};
|
||||||
|
use crate::internal_macros::write_err;
|
||||||
|
|
||||||
/// An error used for dealing with Bitcoin Signed Messages.
|
/// An error used for dealing with Bitcoin Signed Messages.
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "secp-recovery")))]
|
#[cfg_attr(docsrs, doc(cfg(feature = "secp-recovery")))]
|
||||||
|
|
|
@ -30,6 +30,7 @@ use crate::io;
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
|
|
||||||
use crate::consensus::encode;
|
use crate::consensus::encode;
|
||||||
|
use crate::internal_macros::write_err;
|
||||||
|
|
||||||
/// A trait which allows numbers to act as fixed-size bit arrays
|
/// A trait which allows numbers to act as fixed-size bit arrays
|
||||||
pub trait BitArray {
|
pub trait BitArray {
|
||||||
|
|
|
@ -10,6 +10,7 @@ use crate::util::psbt::raw;
|
||||||
|
|
||||||
use crate::hashes;
|
use crate::hashes;
|
||||||
use crate::util::bip32::ExtendedPubKey;
|
use crate::util::bip32::ExtendedPubKey;
|
||||||
|
use crate::internal_macros::write_err;
|
||||||
|
|
||||||
/// Enum for marking psbt hash error.
|
/// Enum for marking psbt hash error.
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||||
|
|
|
@ -207,6 +207,7 @@ mod display_from_str {
|
||||||
use core::str::FromStr;
|
use core::str::FromStr;
|
||||||
use crate::consensus::encode::{Error, self};
|
use crate::consensus::encode::{Error, self};
|
||||||
use base64::display::Base64Display;
|
use base64::display::Base64Display;
|
||||||
|
use crate::internal_macros::write_err;
|
||||||
|
|
||||||
/// Error encountered during PSBT decoding from Base64 string.
|
/// Error encountered during PSBT decoding from Base64 string.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -347,6 +348,7 @@ mod tests {
|
||||||
use crate::util::bip32::{ChildNumber, ExtendedPrivKey, ExtendedPubKey, KeySource};
|
use crate::util::bip32::{ChildNumber, ExtendedPrivKey, ExtendedPubKey, KeySource};
|
||||||
use crate::util::psbt::map::{Output, Input};
|
use crate::util::psbt::map::{Output, Input};
|
||||||
use crate::util::psbt::raw;
|
use crate::util::psbt::raw;
|
||||||
|
use crate::internal_macros::hex_script;
|
||||||
|
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use crate::blockdata::witness::Witness;
|
use crate::blockdata::witness::Witness;
|
||||||
|
@ -492,7 +494,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_serde_psbt() {
|
fn test_serde_psbt() {
|
||||||
//! Create a full PSBT value with various fields filled and make sure it can be JSONized.
|
//! Create a full PSBT value with various fields filled and make sure it can be JSONized.
|
||||||
use hashes::sha256d;
|
use crate::hashes::sha256d;
|
||||||
use crate::util::psbt::map::Input;
|
use crate::util::psbt::map::Input;
|
||||||
use crate::EcdsaSighashType;
|
use crate::EcdsaSighashType;
|
||||||
|
|
||||||
|
@ -602,6 +604,7 @@ mod tests {
|
||||||
use crate::util::psbt::{PartiallySignedTransaction, Error};
|
use crate::util::psbt::{PartiallySignedTransaction, Error};
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use crate::blockdata::witness::Witness;
|
use crate::blockdata::witness::Witness;
|
||||||
|
use crate::internal_macros::hex_script;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic(expected = "InvalidMagic")]
|
#[should_panic(expected = "InvalidMagic")]
|
||||||
|
|
|
@ -14,6 +14,7 @@ use crate::prelude::*;
|
||||||
use secp256k1::{self, Secp256k1, Verification, constants};
|
use secp256k1::{self, Secp256k1, Verification, constants};
|
||||||
use crate::util::taproot::{TapBranchHash, TapTweakHash};
|
use crate::util::taproot::{TapBranchHash, TapTweakHash};
|
||||||
use crate::SchnorrSighashType;
|
use crate::SchnorrSighashType;
|
||||||
|
use crate::internal_macros::write_err;
|
||||||
|
|
||||||
/// Deprecated re-export of [`secp256k1::XOnlyPublicKey`]
|
/// Deprecated re-export of [`secp256k1::XOnlyPublicKey`]
|
||||||
#[deprecated(since = "0.28.0", note = "Please use `util::key::XOnlyPublicKey` instead")]
|
#[deprecated(since = "0.28.0", note = "Please use `util::key::XOnlyPublicKey` instead")]
|
||||||
|
|
|
@ -22,6 +22,7 @@ use crate::io;
|
||||||
use crate::util::taproot::{TapLeafHash, TAPROOT_ANNEX_PREFIX, TapSighashHash};
|
use crate::util::taproot::{TapLeafHash, TAPROOT_ANNEX_PREFIX, TapSighashHash};
|
||||||
use crate::Sighash;
|
use crate::Sighash;
|
||||||
use crate::{Script, Transaction, TxOut};
|
use crate::{Script, Transaction, TxOut};
|
||||||
|
use crate::internal_macros::serde_string_impl;
|
||||||
|
|
||||||
use super::taproot::LeafVersion;
|
use super::taproot::LeafVersion;
|
||||||
|
|
||||||
|
@ -819,6 +820,7 @@ mod tests {
|
||||||
use crate::hashes::hex::ToHex;
|
use crate::hashes::hex::ToHex;
|
||||||
use crate::util::taproot::{TapTweakHash, TapSighashHash, TapBranchHash, TapLeafHash};
|
use crate::util::taproot::{TapTweakHash, TapSighashHash, TapBranchHash, TapLeafHash};
|
||||||
use secp256k1::{self, SecretKey, XOnlyPublicKey};
|
use secp256k1::{self, SecretKey, XOnlyPublicKey};
|
||||||
|
use crate::internal_macros::{hex_hash, hex_script, hex_decode};
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
|
|
||||||
use crate::{Script, Transaction, TxIn, TxOut};
|
use crate::{Script, Transaction, TxIn, TxOut};
|
||||||
|
|
|
@ -13,11 +13,11 @@ use core::convert::TryFrom;
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
use core::cmp::Reverse;
|
use core::cmp::Reverse;
|
||||||
|
|
||||||
use crate::hashes::{sha256, Hash, HashEngine};
|
use crate::hashes::{sha256, sha256t_hash_newtype, Hash, HashEngine};
|
||||||
use crate::schnorr::{TweakedPublicKey, UntweakedPublicKey, TapTweak};
|
use crate::schnorr::{TweakedPublicKey, UntweakedPublicKey, TapTweak};
|
||||||
use crate::util::key::XOnlyPublicKey;
|
use crate::util::key::XOnlyPublicKey;
|
||||||
use crate::Script;
|
use crate::Script;
|
||||||
|
use crate::internal_macros::write_err;
|
||||||
use crate::consensus::Encodable;
|
use crate::consensus::Encodable;
|
||||||
|
|
||||||
/// The SHA-256 midstate value for the TapLeaf hash.
|
/// The SHA-256 midstate value for the TapLeaf hash.
|
||||||
|
@ -49,16 +49,16 @@ const MIDSTATE_TAPSIGHASH: [u8; 32] = [
|
||||||
// f504a425d7f8783b1363868ae3e556586eee945dbc7888dd02a6e2c31873fe9f
|
// f504a425d7f8783b1363868ae3e556586eee945dbc7888dd02a6e2c31873fe9f
|
||||||
|
|
||||||
// Taproot test vectors from BIP-341 state the hashes without any reversing
|
// Taproot test vectors from BIP-341 state the hashes without any reversing
|
||||||
hashes::sha256t_hash_newtype!(TapLeafHash, TapLeafTag, MIDSTATE_TAPLEAF, 64,
|
sha256t_hash_newtype!(TapLeafHash, TapLeafTag, MIDSTATE_TAPLEAF, 64,
|
||||||
doc="Taproot-tagged hash for tapscript Merkle tree leafs", false
|
doc="Taproot-tagged hash for tapscript Merkle tree leafs", false
|
||||||
);
|
);
|
||||||
hashes::sha256t_hash_newtype!(TapBranchHash, TapBranchTag, MIDSTATE_TAPBRANCH, 64,
|
sha256t_hash_newtype!(TapBranchHash, TapBranchTag, MIDSTATE_TAPBRANCH, 64,
|
||||||
doc="Taproot-tagged hash for tapscript Merkle tree branches", false
|
doc="Taproot-tagged hash for tapscript Merkle tree branches", false
|
||||||
);
|
);
|
||||||
hashes::sha256t_hash_newtype!(TapTweakHash, TapTweakTag, MIDSTATE_TAPTWEAK, 64,
|
sha256t_hash_newtype!(TapTweakHash, TapTweakTag, MIDSTATE_TAPTWEAK, 64,
|
||||||
doc="Taproot-tagged hash for public key tweaks", false
|
doc="Taproot-tagged hash for public key tweaks", false
|
||||||
);
|
);
|
||||||
hashes::sha256t_hash_newtype!(TapSighashHash, TapSighashTag, MIDSTATE_TAPSIGHASH, 64,
|
sha256t_hash_newtype!(TapSighashHash, TapSighashTag, MIDSTATE_TAPSIGHASH, 64,
|
||||||
doc="Taproot-tagged hash for the taproot signature hash", false
|
doc="Taproot-tagged hash for the taproot signature hash", false
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ macro_rules! construct_uint {
|
||||||
/// Little-endian large integer type
|
/// Little-endian large integer type
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Default)]
|
#[derive(Copy, Clone, PartialEq, Eq, Hash, Default)]
|
||||||
pub struct $name(pub [u64; $n_words]);
|
pub struct $name(pub [u64; $n_words]);
|
||||||
impl_array_newtype!($name, u64, $n_words);
|
$crate::internal_macros::impl_array_newtype!($name, u64, $n_words);
|
||||||
|
|
||||||
impl $name {
|
impl $name {
|
||||||
/// Conversion to u32
|
/// Conversion to u32
|
||||||
|
@ -404,7 +404,7 @@ macro_rules! construct_uint {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
display_from_debug!($name);
|
$crate::internal_macros::display_from_debug!($name);
|
||||||
|
|
||||||
impl $crate::consensus::Encodable for $name {
|
impl $crate::consensus::Encodable for $name {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
Loading…
Reference in New Issue