bitcoin/
lib.rs

1// Rust Bitcoin Library
2// Written in 2014 by
3//   Andrew Poelstra <apoelstra@wpsoftware.net>
4//
5// To the extent possible under law, the author(s) have dedicated all
6// copyright and related and neighboring rights to this software to
7// the public domain worldwide. This software is distributed without
8// any warranty.
9//
10// You should have received a copy of the CC0 Public Domain Dedication
11// along with this software.
12// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
13//
14
15//! # Rust Bitcoin Library
16//!
17//! This is a library for which supports the Bitcoin network protocol and associated
18//! primitives. It is designed for Rust programs built to work with the Bitcoin
19//! network.
20//!
21//! It is also written entirely in Rust to illustrate the benefits of strong type
22//! safety, including ownership and lifetime, for financial and/or cryptographic
23//! software.
24//!
25
26// Experimental features we need
27#![cfg_attr(all(test, feature = "unstable"), feature(test))]
28
29// Coding conventions
30#![forbid(unsafe_code)]
31#![deny(non_upper_case_globals)]
32#![deny(non_camel_case_types)]
33#![deny(non_snake_case)]
34#![deny(unused_mut)]
35#![deny(dead_code)]
36#![deny(unused_imports)]
37#![deny(missing_docs)]
38#![deny(unused_must_use)]
39
40// Re-exported dependencies.
41#[macro_use] pub extern crate bitcoin_hashes as hashes;
42pub extern crate secp256k1zkp as secp256k1;
43pub extern crate bech32;
44#[cfg(feature = "base64")] pub extern crate base64;
45
46#[cfg(feature="bitcoinconsensus")] extern crate bitcoinconsensus;
47#[cfg(feature = "serde")] #[macro_use] extern crate serde;
48#[cfg(all(test, feature = "serde"))] extern crate serde_json;
49#[cfg(all(test, feature = "serde"))] extern crate serde_test;
50#[cfg(all(test, feature = "unstable"))] extern crate test;
51
52#[cfg(target_pointer_width = "16")]
53compile_error!("rust-bitcoin cannot be used on 16-bit architectures");
54
55#[cfg(test)]
56#[macro_use]
57mod test_macros;
58#[macro_use]
59mod internal_macros;
60#[cfg(feature = "serde")]
61mod serde_utils;
62
63#[macro_use]
64pub mod network;
65pub mod blockdata;
66pub mod util;
67pub mod consensus;
68pub mod hash_types;
69
70pub use hash_types::*;
71pub use blockdata::block::Block;
72pub use blockdata::block::BlockHeader;
73pub use blockdata::script::Script;
74pub use blockdata::transaction::Transaction;
75pub use blockdata::transaction::TxIn;
76pub use blockdata::transaction::TxOut;
77pub use blockdata::transaction::OutPoint;
78pub use blockdata::transaction::SigHashType;
79pub use consensus::encode::VarInt;
80pub use network::constants::Network;
81pub use util::Error;
82pub use util::address::Address;
83pub use util::address::AddressType;
84pub use util::amount::Amount;
85pub use util::amount::Denomination;
86pub use util::amount::SignedAmount;
87pub use util::key::PrivateKey;
88pub use util::key::PublicKey;
89pub use util::merkleblock::MerkleBlock;
90
91#[cfg(all(test, feature = "unstable"))] use tests::EmptyWrite;
92
93#[cfg(all(test, feature = "unstable"))]
94mod tests {
95    use hashes::core::fmt::Arguments;
96    use std::io::{IoSlice, Result, Write};
97
98    #[derive(Default, Clone, Debug, PartialEq, Eq)]
99    pub struct EmptyWrite;
100
101    impl Write for EmptyWrite {
102        fn write(&mut self, buf: &[u8]) -> Result<usize> {
103            Ok(buf.len())
104        }
105        fn write_vectored(&mut self, bufs: &[IoSlice]) -> Result<usize> {
106            Ok(bufs.iter().map(|s| s.len()).sum())
107        }
108        fn flush(&mut self) -> Result<()> {
109            Ok(())
110        }
111
112        fn write_all(&mut self, _: &[u8]) -> Result<()> {
113            Ok(())
114        }
115        fn write_fmt(&mut self, _: Arguments) -> Result<()> {
116            Ok(())
117        }
118    }
119}