2014-07-18 13:56:17 +00:00
|
|
|
// Rust Bitcoin Library
|
|
|
|
// Written in 2014 by
|
|
|
|
// Andrew Poelstra <apoelstra@wpsoftware.net>
|
|
|
|
//
|
|
|
|
// To the extent possible under law, the author(s) have dedicated all
|
|
|
|
// copyright and related and neighboring rights to this software to
|
|
|
|
// the public domain worldwide. This software is distributed without
|
|
|
|
// any warranty.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the CC0 Public Domain Dedication
|
|
|
|
// along with this software.
|
|
|
|
// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
|
|
|
|
//
|
|
|
|
|
|
|
|
//! # Rust Bitcoin Library
|
|
|
|
//!
|
|
|
|
//! This is a library for which supports the Bitcoin network protocol and associated
|
|
|
|
//! primitives. It is designed for Rust programs built to work with the Bitcoin
|
|
|
|
//! network.
|
|
|
|
//!
|
|
|
|
//! It is also written entirely in Rust to illustrate the benefits of strong type
|
|
|
|
//! safety, including ownership and lifetime, for financial and/or cryptographic
|
|
|
|
//! software.
|
|
|
|
//!
|
|
|
|
|
|
|
|
// Experimental features we need
|
2015-09-20 17:22:39 +00:00
|
|
|
#![cfg_attr(all(test, feature = "unstable"), feature(test))]
|
2014-07-18 13:56:17 +00:00
|
|
|
|
|
|
|
// Coding conventions
|
2019-02-20 22:16:21 +00:00
|
|
|
#![forbid(unsafe_code)]
|
2015-04-11 01:55:59 +00:00
|
|
|
#![deny(non_upper_case_globals)]
|
2014-07-18 13:56:17 +00:00
|
|
|
#![deny(non_camel_case_types)]
|
2014-08-30 23:08:38 +00:00
|
|
|
#![deny(non_snake_case)]
|
2014-07-18 13:56:17 +00:00
|
|
|
#![deny(unused_mut)]
|
2019-08-18 16:26:29 +00:00
|
|
|
#![deny(dead_code)]
|
|
|
|
#![deny(unused_imports)]
|
2015-04-11 01:55:59 +00:00
|
|
|
#![deny(missing_docs)]
|
2020-10-23 16:21:54 +00:00
|
|
|
#![deny(unused_must_use)]
|
2019-07-23 21:29:45 +00:00
|
|
|
|
2019-07-06 13:43:12 +00:00
|
|
|
// Re-exported dependencies.
|
2019-12-09 22:37:52 +00:00
|
|
|
#[macro_use] pub extern crate bitcoin_hashes as hashes;
|
2019-07-06 13:43:12 +00:00
|
|
|
pub extern crate secp256k1;
|
2019-08-16 20:08:14 +00:00
|
|
|
pub extern crate bech32;
|
2020-10-07 15:46:48 +00:00
|
|
|
#[cfg(feature = "base64")] pub extern crate base64;
|
2019-07-06 13:43:12 +00:00
|
|
|
|
2020-09-14 14:57:42 +00:00
|
|
|
#[cfg(feature="bitcoinconsensus")] extern crate bitcoinconsensus;
|
2020-10-25 18:03:20 +00:00
|
|
|
#[cfg(feature = "serde")] #[macro_use] extern crate serde;
|
2018-11-10 00:45:00 +00:00
|
|
|
#[cfg(all(test, feature = "serde"))] extern crate serde_json;
|
|
|
|
#[cfg(all(test, feature = "serde"))] extern crate serde_test;
|
2021-01-05 22:01:21 +00:00
|
|
|
#[cfg(all(test, feature = "serde"))] extern crate bincode;
|
2015-09-20 17:22:39 +00:00
|
|
|
#[cfg(all(test, feature = "unstable"))] extern crate test;
|
2014-07-18 13:56:17 +00:00
|
|
|
|
2019-06-05 13:59:44 +00:00
|
|
|
#[cfg(target_pointer_width = "16")]
|
|
|
|
compile_error!("rust-bitcoin cannot be used on 16-bit architectures");
|
|
|
|
|
2015-04-10 23:15:57 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
#[macro_use]
|
|
|
|
mod test_macros;
|
2015-01-18 18:16:01 +00:00
|
|
|
#[macro_use]
|
2014-07-18 13:56:17 +00:00
|
|
|
mod internal_macros;
|
2020-10-25 18:27:45 +00:00
|
|
|
#[cfg(feature = "serde")]
|
|
|
|
mod serde_utils;
|
|
|
|
|
2015-01-18 18:16:01 +00:00
|
|
|
#[macro_use]
|
2014-07-18 13:56:17 +00:00
|
|
|
pub mod network;
|
|
|
|
pub mod blockdata;
|
|
|
|
pub mod util;
|
Move relevant names into consensus::encode
- Move network::encodable::* to consensus::encode::*
- Rename Consensus{En,De}codable to {En,De}codable (now under
consensus::encode)
- Move network::serialize::Error to consensus::encode::Error
- Remove Raw{En,De}coder, implement {En,De}coder for T: {Write,Read}
instead
- Move network::serialize::Simple{En,De}coder to
consensus::encode::{En,De}coder
- Rename util::Error::Serialize to util::Error::Encode
- Modify comments to refer to new names
- Modify files to refer to new names
- Expose {En,De}cod{able,er}, {de,}serialize, Params
- Do not return Result for serialize{,_hex} as serializing to a Vec
should never fail
2018-09-20 10:15:45 +00:00
|
|
|
pub mod consensus;
|
2019-12-09 22:37:52 +00:00
|
|
|
pub mod hash_types;
|
2018-08-28 15:57:46 +00:00
|
|
|
|
2019-12-09 22:37:52 +00:00
|
|
|
pub use hash_types::*;
|
2018-08-28 15:57:46 +00:00
|
|
|
pub use blockdata::block::Block;
|
|
|
|
pub use blockdata::block::BlockHeader;
|
|
|
|
pub use blockdata::script::Script;
|
|
|
|
pub use blockdata::transaction::Transaction;
|
|
|
|
pub use blockdata::transaction::TxIn;
|
|
|
|
pub use blockdata::transaction::TxOut;
|
|
|
|
pub use blockdata::transaction::OutPoint;
|
|
|
|
pub use blockdata::transaction::SigHashType;
|
Move relevant names into consensus::encode
- Move network::encodable::* to consensus::encode::*
- Rename Consensus{En,De}codable to {En,De}codable (now under
consensus::encode)
- Move network::serialize::Error to consensus::encode::Error
- Remove Raw{En,De}coder, implement {En,De}coder for T: {Write,Read}
instead
- Move network::serialize::Simple{En,De}coder to
consensus::encode::{En,De}coder
- Rename util::Error::Serialize to util::Error::Encode
- Modify comments to refer to new names
- Modify files to refer to new names
- Expose {En,De}cod{able,er}, {de,}serialize, Params
- Do not return Result for serialize{,_hex} as serializing to a Vec
should never fail
2018-09-20 10:15:45 +00:00
|
|
|
pub use consensus::encode::VarInt;
|
2018-10-21 22:28:27 +00:00
|
|
|
pub use network::constants::Network;
|
2018-08-28 15:57:46 +00:00
|
|
|
pub use util::Error;
|
|
|
|
pub use util::address::Address;
|
2019-07-16 20:31:49 +00:00
|
|
|
pub use util::address::AddressType;
|
2018-11-10 00:45:00 +00:00
|
|
|
pub use util::amount::Amount;
|
2020-02-28 11:51:44 +00:00
|
|
|
pub use util::amount::Denomination;
|
2018-11-10 00:45:00 +00:00
|
|
|
pub use util::amount::SignedAmount;
|
2018-11-15 21:55:33 +00:00
|
|
|
pub use util::key::PrivateKey;
|
|
|
|
pub use util::key::PublicKey;
|
2019-05-27 12:36:35 +00:00
|
|
|
pub use util::merkleblock::MerkleBlock;
|
2020-03-29 12:54:15 +00:00
|
|
|
|
|
|
|
#[cfg(all(test, feature = "unstable"))] use tests::EmptyWrite;
|
|
|
|
|
|
|
|
#[cfg(all(test, feature = "unstable"))]
|
|
|
|
mod tests {
|
|
|
|
use hashes::core::fmt::Arguments;
|
|
|
|
use std::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_vectored(&mut self, bufs: &[IoSlice]) -> Result<usize> {
|
|
|
|
Ok(bufs.iter().map(|s| s.len()).sum())
|
|
|
|
}
|
|
|
|
fn flush(&mut self) -> Result<()> {
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn write_all(&mut self, _: &[u8]) -> Result<()> {
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
fn write_fmt(&mut self, _: Arguments) -> Result<()> {
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|