1#![cfg_attr(all(not(feature = "std"), not(test)), no_std)]
32#![cfg_attr(bench, feature(test))]
34#![warn(missing_docs)]
36#![cfg_attr(fuzzing, allow(dead_code, unused_imports))]
38#![allow(clippy::needless_question_mark)] #![allow(clippy::manual_range_contains)] #![allow(clippy::needless_borrows_for_generic_args)] #![allow(deprecated)]
44
45#[cfg(target_pointer_width = "16")]
47compile_error!(
48 "rust-bitcoin currently only supports architectures with pointers wider than 16 bits, let us
49 know if you want 16-bit support. Note that we do NOT guarantee that we will implement it!"
50);
51
52#[cfg(bench)]
53extern crate test;
54
55#[macro_use]
56extern crate alloc;
57
58#[cfg(feature = "base64")]
59pub extern crate base64;
61
62pub extern crate base58;
64
65pub extern crate bech32;
67
68pub extern crate hashes;
70
71pub extern crate hex;
73
74pub extern crate io;
76
77#[cfg(feature = "ordered")]
79pub extern crate ordered;
80
81pub extern crate secp256k1;
84
85#[cfg(feature = "serde")]
86#[macro_use]
87extern crate actual_serde as serde;
88
89#[cfg(test)]
90#[macro_use]
91mod test_macros;
92mod internal_macros;
93#[cfg(feature = "serde")]
94mod serde_utils;
95
96#[macro_use]
97pub mod p2p;
98pub mod address;
99pub mod bip152;
100pub mod bip158;
101pub mod bip32;
102pub mod blockdata;
103pub mod consensus;
104pub(crate) mod crypto;
106pub mod error;
107pub mod hash_types;
108pub mod merkle_tree;
109pub mod network;
110pub mod policy;
111pub mod pow;
112pub mod psbt;
113pub mod sign_message;
114pub mod taproot;
115
116#[rustfmt::skip] #[doc(inline)]
118pub use crate::{
119 address::{Address, AddressType, KnownHrp},
120 amount::{Amount, Denomination, SignedAmount},
121 bip158::{FilterHash, FilterHeader},
122 bip32::XKeyIdentifier,
123 blockdata::block::{self, Block, BlockHash, TxMerkleNode, WitnessMerkleNode, WitnessCommitment},
124 blockdata::constants,
125 blockdata::fee_rate::FeeRate,
126 blockdata::locktime::{self, absolute, relative},
127 blockdata::opcodes::{self, Opcode},
128 blockdata::script::witness_program::{self, WitnessProgram},
129 blockdata::script::witness_version::{self, WitnessVersion},
130 blockdata::script::{self, Script, ScriptBuf, ScriptHash, WScriptHash},
131 blockdata::transaction::{self, OutPoint, Sequence, Transaction, TxIn, TxOut, Txid, Wtxid},
132 blockdata::weight::Weight,
133 blockdata::witness::{self, Witness},
134 consensus::encode::VarInt,
135 consensus::params,
136 crypto::ecdsa,
137 crypto::key::{self, PrivateKey, PubkeyHash, PublicKey, CompressedPublicKey, WPubkeyHash, XOnlyPublicKey},
138 crypto::sighash::{self, LegacySighash, SegwitV0Sighash, TapSighash, TapSighashTag},
139 merkle_tree::MerkleBlock,
140 network::{Network, NetworkKind},
141 pow::{CompactTarget, Target, Work},
142 psbt::Psbt,
143 sighash::{EcdsaSighashType, TapSighashType},
144 taproot::{TapBranchTag, TapLeafHash, TapLeafTag, TapNodeHash, TapTweakHash, TapTweakTag},
145};
146
147#[rustfmt::skip]
148#[allow(unused_imports)]
149mod prelude {
150 #[cfg(all(not(feature = "std"), not(test)))]
151 pub use alloc::{string::{String, ToString}, vec::Vec, boxed::Box, borrow::{Borrow, BorrowMut, Cow, ToOwned}, slice, rc};
152
153 #[cfg(all(not(feature = "std"), not(test), any(not(rust_v_1_60), target_has_atomic = "ptr")))]
154 pub use alloc::sync;
155
156 #[cfg(any(feature = "std", test))]
157 pub use std::{string::{String, ToString}, vec::Vec, boxed::Box, borrow::{Borrow, BorrowMut, Cow, ToOwned}, rc, sync};
158
159 #[cfg(all(not(feature = "std"), not(test)))]
160 pub use alloc::collections::{BTreeMap, BTreeSet, btree_map, BinaryHeap};
161
162 #[cfg(any(feature = "std", test))]
163 pub use std::collections::{BTreeMap, BTreeSet, btree_map, BinaryHeap};
164
165 pub use crate::io::sink;
166
167 pub use hex::DisplayHex;
168}
169
170pub mod amount {
171 use crate::consensus::{encode, Decodable, Encodable};
177 use crate::io::{Read, Write};
178
179 #[rustfmt::skip] #[doc(inline)]
181 pub use units::amount::{
182 Amount, CheckedSum, Denomination, Display, ParseAmountError, SignedAmount,
183 };
184 #[cfg(feature = "serde")]
185 pub use units::amount::serde;
186
187 impl Decodable for Amount {
188 #[inline]
189 fn consensus_decode<R: Read + ?Sized>(r: &mut R) -> Result<Self, encode::Error> {
190 Ok(Amount::from_sat(Decodable::consensus_decode(r)?))
191 }
192 }
193
194 impl Encodable for Amount {
195 #[inline]
196 fn consensus_encode<W: Write + ?Sized>(&self, w: &mut W) -> Result<usize, io::Error> {
197 self.to_sat().consensus_encode(w)
198 }
199 }
200}
201
202pub mod parse {
204 pub use units::parse::ParseIntError;
206}