bitcoin/blockdata/
mod.rs

1// SPDX-License-Identifier: CC0-1.0
2
3//! Bitcoin block data.
4//!
5//! This module defines structures and functions for storing the blocks and
6//! transactions which make up the Bitcoin system.
7//!
8
9pub mod block;
10pub mod constants;
11pub mod locktime;
12pub mod opcodes;
13pub mod script;
14pub mod transaction;
15pub mod witness;
16
17#[rustfmt::skip]                // Keep public re-exports separate.
18#[doc(inline)]
19pub use self::{
20    fee_rate::FeeRate,
21    weight::Weight
22};
23
24/// Implements `FeeRate` and assoctiated features.
25pub mod fee_rate {
26    /// Re-export everything from the [`units::fee_rate`] module.
27    pub use units::fee_rate::*;
28
29    #[cfg(test)]
30    mod tests {
31        use super::*;
32
33        #[test]
34        fn fee_convenience_functions_agree() {
35            use hex::test_hex_unwrap as hex;
36
37            use crate::blockdata::transaction::Transaction;
38            use crate::consensus::Decodable;
39
40            const SOME_TX: &str = "0100000001a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff0100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000";
41
42            let raw_tx = hex!(SOME_TX);
43            let tx: Transaction = Decodable::consensus_decode(&mut raw_tx.as_slice()).unwrap();
44
45            let rate = FeeRate::from_sat_per_vb(1).expect("1 sat/byte is valid");
46
47            assert_eq!(rate.fee_vb(tx.vsize() as u64), rate.fee_wu(tx.weight()));
48        }
49    }
50}
51
52/// Implements `Weight` and associated features.
53pub mod weight {
54    /// Re-export everything from the [`units::weight`] module.
55    pub use units::weight::*;
56}