1#![cfg_attr(all(not(feature = "std"), not(test)), no_std)]
35#![cfg_attr(bench, feature(test))]
37#![cfg_attr(docsrs, feature(doc_cfg))]
38#![warn(missing_docs)]
40#![cfg_attr(fuzzing, allow(dead_code, unused_imports))]
42
43#[cfg(not(any(feature = "std", feature = "no-std")))]
44compile_error!("at least one of the `std` or `no-std` features must be enabled");
45
46#[cfg(target_pointer_width = "16")]
48compile_error!(
49 "rust-bitcoin currently only supports architectures with pointers wider than 16 bits, let us
50 know if you want 16-bit support. Note that we do NOT guarantee that we will implement it!"
51);
52
53#[cfg(bench)]
54extern crate test;
55
56#[macro_use]
57extern crate alloc;
58
59#[cfg(feature = "base64")]
60#[cfg_attr(docsrs, doc(cfg(feature = "base64")))]
61pub extern crate base64;
62pub extern crate bech32;
63pub extern crate bitcoin_hashes as hashes;
64#[cfg(feature = "bitcoinconsensus")]
65#[cfg_attr(docsrs, doc(cfg(feature = "bitcoinconsensus")))]
66pub extern crate bitcoinconsensus;
67pub extern crate hex;
68pub extern crate secp256k1;
69
70#[cfg(feature = "serde")]
71#[macro_use]
72extern crate actual_serde as serde;
73
74#[cfg(test)]
75#[macro_use]
76mod test_macros;
77mod internal_macros;
78mod parse;
79#[cfg(feature = "serde")]
80mod serde_utils;
81
82#[macro_use]
83pub mod network;
84pub mod address;
85pub mod amount;
86pub mod base58;
87pub mod bip152;
88pub mod bip158;
89pub mod bip32;
90pub mod blockdata;
91pub mod consensus;
92pub(crate) mod crypto;
94pub mod error;
95pub mod hash_types;
96pub mod merkle_tree;
97pub mod policy;
98pub mod pow;
99pub mod psbt;
100pub mod sign_message;
101pub mod string;
102pub mod taproot;
103pub mod util;
104
105#[allow(unused)]
107#[cfg(feature = "std")]
108use std::error::Error as StdError;
109#[cfg(feature = "std")]
110use std::io;
111
112#[allow(unused)]
113#[cfg(not(feature = "std"))]
114use core2::error::Error as StdError;
115#[cfg(not(feature = "std"))]
116use core2::io;
117
118pub use crate::address::{Address, AddressType};
119pub use crate::amount::{Amount, Denomination, SignedAmount};
120pub use crate::blockdata::block::{self, Block};
121pub use crate::blockdata::fee_rate::FeeRate;
122pub use crate::blockdata::locktime::{self, absolute, relative};
123pub use crate::blockdata::script::{self, Script, ScriptBuf};
124pub use crate::blockdata::transaction::{self, OutPoint, Sequence, Transaction, TxIn, TxOut};
125pub use crate::blockdata::weight::Weight;
126pub use crate::blockdata::witness::{self, Witness};
127pub use crate::blockdata::{constants, opcodes};
128pub use crate::consensus::encode::VarInt;
129pub use crate::crypto::key::{self, PrivateKey, PublicKey};
130pub use crate::crypto::{ecdsa, sighash};
131pub use crate::error::Error;
132pub use crate::hash_types::{
133 BlockHash, PubkeyHash, ScriptHash, Txid, WPubkeyHash, WScriptHash, Wtxid,
134};
135pub use crate::merkle_tree::MerkleBlock;
136pub use crate::network::constants::Network;
137pub use crate::pow::{CompactTarget, Target, Work};
138
139#[cfg(not(feature = "std"))]
140mod io_extras {
141 pub struct Sink {
143 _priv: (),
144 }
145
146 pub const fn sink() -> Sink {
148 Sink { _priv: () }
149 }
150
151 impl core2::io::Write for Sink {
152 #[inline]
153 fn write(&mut self, buf: &[u8]) -> core2::io::Result<usize> {
154 Ok(buf.len())
155 }
156
157 #[inline]
158 fn flush(&mut self) -> core2::io::Result<()> {
159 Ok(())
160 }
161 }
162}
163
164#[rustfmt::skip]
165mod prelude {
166 #[cfg(all(not(feature = "std"), not(test)))]
167 pub use alloc::{string::{String, ToString}, vec::Vec, boxed::Box, borrow::{Borrow, Cow, ToOwned}, slice, rc};
168
169 #[cfg(all(not(feature = "std"), not(test), any(not(rust_v_1_60), target_has_atomic = "ptr")))]
170 pub use alloc::sync;
171
172 #[cfg(any(feature = "std", test))]
173 pub use std::{string::{String, ToString}, vec::Vec, boxed::Box, borrow::{Borrow, Cow, ToOwned}, slice, rc, sync};
174
175 #[cfg(all(not(feature = "std"), not(test)))]
176 pub use alloc::collections::{BTreeMap, BTreeSet, btree_map, BinaryHeap};
177
178 #[cfg(any(feature = "std", test))]
179 pub use std::collections::{BTreeMap, BTreeSet, btree_map, BinaryHeap};
180
181 #[cfg(feature = "std")]
182 pub use std::io::sink;
183
184 #[cfg(not(feature = "std"))]
185 pub use crate::io_extras::sink;
186
187 pub use bitcoin_internals::hex::display::DisplayHex;
188}
189
190#[cfg(bench)]
191use bench::EmptyWrite;
192
193#[cfg(bench)]
194mod bench {
195 use core::fmt::Arguments;
196
197 use crate::io::{IoSlice, Result, Write};
198
199 #[derive(Default, Clone, Debug, PartialEq, Eq)]
200 pub struct EmptyWrite;
201
202 impl Write for EmptyWrite {
203 fn write(&mut self, buf: &[u8]) -> Result<usize> {
204 Ok(buf.len())
205 }
206 fn write_vectored(&mut self, bufs: &[IoSlice]) -> Result<usize> {
207 Ok(bufs.iter().map(|s| s.len()).sum())
208 }
209 fn flush(&mut self) -> Result<()> {
210 Ok(())
211 }
212
213 fn write_all(&mut self, _: &[u8]) -> Result<()> {
214 Ok(())
215 }
216 fn write_fmt(&mut self, _: Arguments) -> Result<()> {
217 Ok(())
218 }
219 }
220}