reth_primitives_traits/
lib.rs

1//! Commonly used types and traits in Reth.
2//!
3//! This crate contains various primitive traits used across reth's components.
4//! It provides the [`Block`] trait which is used to represent a block and all its components.
5//! A [`Block`] is composed of a [`Header`] and a [`BlockBody`]. In ethereum (and optimism), a block
6//! body consists of a list of transactions, a list of uncle headers, and a list of withdrawals. For
7//! optimism, uncle headers and withdrawals are always empty lists.
8//!
9//! ## Feature Flags
10//!
11//! - `arbitrary`: Adds `proptest` and `arbitrary` support for primitive types.
12//! - `op`: Implements the traits for various [op-alloy](https://github.com/alloy-rs/op-alloy)
13//!   types.
14//! - `reth-codec`: Enables db codec support for reth types including zstd compression for certain
15//!   types.
16//! - `serde`: Adds serde support for all types.
17//! - `secp256k1`: Adds secp256k1 support for transaction signing/recovery. (By default the no-std
18//!   friendly `k256` is used)
19
20#![doc(
21    html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png",
22    html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256",
23    issue_tracker_base_url = "https://github.com/SeismicSystems/seismic-reth/issues/"
24)]
25#![cfg_attr(not(test), warn(unused_crate_dependencies))]
26#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
27#![cfg_attr(not(feature = "std"), no_std)]
28
29#[macro_use]
30extern crate alloc;
31
32/// Common constants.
33pub mod constants;
34pub use constants::gas_units::{format_gas, format_gas_throughput};
35
36/// Minimal account
37pub mod account;
38pub use account::{Account, Bytecode};
39
40pub mod receipt;
41pub use receipt::{FullReceipt, Receipt};
42
43pub mod transaction;
44pub use transaction::{
45    execute::FillTxEnv,
46    signed::{FullSignedTx, SignedTransaction},
47    FullTransaction, Transaction,
48};
49
50pub mod block;
51pub use block::{
52    body::{BlockBody, FullBlockBody},
53    header::{BlockHeader, FullBlockHeader},
54    Block, FullBlock,
55};
56
57mod encoded;
58mod withdrawal;
59pub use encoded::WithEncoded;
60
61pub mod crypto;
62
63mod error;
64pub use error::{GotExpected, GotExpectedBoxed};
65
66mod log;
67pub use alloy_primitives::{logs_bloom, Log, LogData};
68
69mod storage;
70pub use storage::StorageEntry;
71
72/// Common header types
73pub mod header;
74#[cfg(any(test, feature = "arbitrary", feature = "test-utils"))]
75pub use header::test_utils;
76pub use header::{Header, HeaderError, SealedHeader};
77
78/// Bincode-compatible serde implementations for common abstracted types in Reth.
79///
80/// `bincode` crate doesn't work with optionally serializable serde fields, but some of the
81/// Reth types require optional serialization for RPC compatibility. This module makes so that
82/// all fields are serialized.
83///
84/// Read more: <https://github.com/bincode-org/bincode/issues/326>
85#[cfg(feature = "serde-bincode-compat")]
86pub mod serde_bincode_compat;
87
88/// Heuristic size trait
89pub mod size;
90pub use size::InMemorySize;
91
92/// Node traits
93pub mod node;
94pub use node::{BodyTy, FullNodePrimitives, HeaderTy, NodePrimitives, ReceiptTy};
95
96/// Helper trait that requires de-/serialize implementation since `serde` feature is enabled.
97#[cfg(feature = "serde")]
98pub trait MaybeSerde: serde::Serialize + for<'de> serde::Deserialize<'de> {}
99/// Noop. Helper trait that would require de-/serialize implementation if `serde` feature were
100/// enabled.
101#[cfg(not(feature = "serde"))]
102pub trait MaybeSerde {}
103
104#[cfg(feature = "serde")]
105impl<T> MaybeSerde for T where T: serde::Serialize + for<'de> serde::Deserialize<'de> {}
106#[cfg(not(feature = "serde"))]
107impl<T> MaybeSerde for T {}
108
109/// Helper trait that requires database encoding implementation since `reth-codec` feature is
110/// enabled.
111#[cfg(feature = "reth-codec")]
112pub trait MaybeCompact: reth_codecs::Compact {}
113/// Noop. Helper trait that would require database encoding implementation if `reth-codec` feature
114/// were enabled.
115#[cfg(not(feature = "reth-codec"))]
116pub trait MaybeCompact {}
117
118#[cfg(feature = "reth-codec")]
119impl<T> MaybeCompact for T where T: reth_codecs::Compact {}
120#[cfg(not(feature = "reth-codec"))]
121impl<T> MaybeCompact for T {}
122
123/// Helper trait that requires serde bincode compatibility implementation.
124#[cfg(feature = "serde-bincode-compat")]
125pub trait MaybeSerdeBincodeCompat: crate::serde_bincode_compat::SerdeBincodeCompat {}
126/// Noop. Helper trait that would require serde bincode compatibility implementation if
127/// `serde-bincode-compat` feature were enabled.
128#[cfg(not(feature = "serde-bincode-compat"))]
129pub trait MaybeSerdeBincodeCompat {}
130
131#[cfg(feature = "serde-bincode-compat")]
132impl<T> MaybeSerdeBincodeCompat for T where T: crate::serde_bincode_compat::SerdeBincodeCompat {}
133#[cfg(not(feature = "serde-bincode-compat"))]
134impl<T> MaybeSerdeBincodeCompat for T {}