Skip to content

Commit

Permalink
feat: Move AnyReceipt and AnyHeader to alloy-consensus-any (#1609)
Browse files Browse the repository at this point in the history
* Move `AnyReceipt` and `AnyHeader` to `alloy-consensus-any`

* enable serde feature

* remove unnecessary files

* tidy up Cargo.toml

* fix deps

* Move `AnyTransactionReceipt` to `rpc-types-any`

* Move AnyRpcHeader to rpc-types-any

* Remove `serde` feature from rpc-types-any

* fix reexports

---------

Co-authored-by: Arsenii Kulikov <[email protected]>
  • Loading branch information
moricho and klkvr authored Nov 19, 2024
1 parent fd6cd0f commit 30ee13f
Show file tree
Hide file tree
Showing 24 changed files with 284 additions and 170 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ rustdoc-args = ["--cfg", "docsrs"]

[workspace.dependencies]
alloy-consensus = { version = "0.6", path = "crates/consensus", default-features = false }
alloy-consensus-any = { version = "0.6", path = "crates/consensus-any", default-features = false }
alloy-contract = { version = "0.6", path = "crates/contract", default-features = false }
alloy-eips = { version = "0.6", path = "crates/eips", default-features = false }
alloy-eip7547 = { version = "0.6", path = "crates/eip7547", default-features = false }
Expand All @@ -49,6 +50,7 @@ alloy-pubsub = { version = "0.6", path = "crates/pubsub", default-features = fal
alloy-rpc-client = { version = "0.6", path = "crates/rpc-client", default-features = false }
alloy-rpc-types-admin = { version = "0.6", path = "crates/rpc-types-admin", default-features = false }
alloy-rpc-types-anvil = { version = "0.6", path = "crates/rpc-types-anvil", default-features = false }
alloy-rpc-types-any = { version = "0.6", path = "crates/rpc-types-any", default-features = false }
alloy-rpc-types-beacon = { version = "0.6", path = "crates/rpc-types-beacon", default-features = false }
alloy-rpc-types-debug = { version = "0.6", path = "crates/rpc-types-debug", default-features = false }
alloy-rpc-types-engine = { version = "0.6", path = "crates/rpc-types-engine", default-features = false }
Expand Down
46 changes: 46 additions & 0 deletions crates/consensus-any/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[package]
name = "alloy-consensus-any"
description = "Consensus interface for any network"

version.workspace = true
edition.workspace = true
rust-version.workspace = true
authors.workspace = true
license.workspace = true
homepage.workspace = true
repository.workspace = true
exclude.workspace = true

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[lints]
workspace = true

[dependencies]
alloy-consensus = { workspace = true, features = ["serde"] }
alloy-eips.workspace = true
alloy-primitives.workspace = true
alloy-rlp.workspace = true
alloy-serde = { workspace = true, optional = true }

# arbitrary
arbitrary = { workspace = true, features = ["derive"], optional = true }

# serde
serde = { workspace = true, features = ["derive"], optional = true }

[dev-dependencies]
arbitrary = { workspace = true, features = ["derive"] }

[features]
default = ["std"]
std = ["alloy-eips/std"]
arbitrary = ["std", "dep:arbitrary", "alloy-eips/arbitrary"]
serde = [
"dep:serde",
"alloy-primitives/serde",
"dep:alloy-serde",
"alloy-eips/serde",
]
3 changes: 3 additions & 0 deletions crates/consensus-any/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# alloy-consensus-any

Consensus interface for any network.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use alloy_consensus::{BlockHeader, Header};
use alloy_primitives::{Address, BlockNumber, Bloom, Bytes, B256, B64, U256};

use super::{BlockHeader, Header};

/// Block header representation with certain fields made optional to account for possible
/// differencies in network implementations.
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
Expand Down Expand Up @@ -184,8 +183,8 @@ impl BlockHeader for AnyHeader {
}
}

impl From<super::Header> for AnyHeader {
fn from(value: super::Header) -> Self {
impl From<Header> for AnyHeader {
fn from(value: Header) -> Self {
let Header {
parent_hash,
ommers_hash,
Expand Down
2 changes: 2 additions & 0 deletions crates/consensus-any/src/block/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod header;
pub use header::AnyHeader;
14 changes: 14 additions & 0 deletions crates/consensus-any/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#![doc = include_str!("../README.md")]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/alloy.jpg",
html_favicon_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/favicon.ico"
)]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![cfg_attr(not(feature = "std"), no_std)]

mod block;
pub use block::AnyHeader;

mod receipt;
pub use receipt::AnyReceiptEnvelope;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{Eip658Value, ReceiptWithBloom, TxReceipt};
use alloy_consensus::{Eip658Value, ReceiptWithBloom, TxReceipt};
use alloy_eips::eip2718::{Decodable2718, Eip2718Result, Encodable2718};
use alloy_primitives::{bytes::BufMut, Bloom, Log};
use alloy_rlp::{Decodable, Encodable};
Expand Down
2 changes: 2 additions & 0 deletions crates/consensus-any/src/receipt/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod envelope;
pub use envelope::AnyReceiptEnvelope;
2 changes: 1 addition & 1 deletion crates/consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ derive_more = { workspace = true, features = [
"from",
"deref",
"deref_mut",
"into_iterator"
"into_iterator",
], default-features = false }
auto_impl.workspace = true

Expand Down
2 changes: 0 additions & 2 deletions crates/consensus/src/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
mod header;
pub use header::{BlockHeader, Header};
mod any;
pub use any::AnyHeader;

#[cfg(all(feature = "serde", feature = "serde-bincode-compat"))]
pub(crate) use header::serde_bincode_compat;
Expand Down
7 changes: 2 additions & 5 deletions crates/consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,13 @@ mod account;
pub use account::Account;

mod block;
pub use block::{AnyHeader, Block, BlockBody, BlockHeader, Header};
pub use block::{Block, BlockBody, BlockHeader, Header};

pub mod constants;
pub use constants::{EMPTY_OMMER_ROOT_HASH, EMPTY_ROOT_HASH};

mod receipt;
pub use receipt::{
AnyReceiptEnvelope, Eip658Value, Receipt, ReceiptEnvelope, ReceiptWithBloom, Receipts,
TxReceipt,
};
pub use receipt::{Eip658Value, Receipt, ReceiptEnvelope, ReceiptWithBloom, Receipts, TxReceipt};

pub mod proofs;

Expand Down
3 changes: 0 additions & 3 deletions crates/consensus/src/receipt/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use alloy_primitives::{Bloom, Log};
use core::fmt;

mod any;
pub use any::AnyReceiptEnvelope;

mod envelope;
pub use envelope::ReceiptEnvelope;

Expand Down
2 changes: 2 additions & 0 deletions crates/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ workspace = true

[dependencies]
alloy-consensus = { workspace = true, features = ["std"] }
alloy-consensus-any = { workspace = true, features = ["std", "serde"] }
alloy-eips = { workspace = true, features = ["serde"] }
alloy-json-rpc.workspace = true
alloy-network-primitives.workspace = true
alloy-primitives = { workspace = true, features = ["map"] }
alloy-rpc-types-any.workspace = true
alloy-rpc-types-eth = { workspace = true, features = ["std", "serde"] }
alloy-signer.workspace = true
alloy-serde.workspace = true
Expand Down
12 changes: 5 additions & 7 deletions crates/network/src/any/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ pub use either::{AnyTxEnvelope, AnyTypedTransaction};
mod unknowns;
pub use unknowns::{AnyTxType, UnknownTxEnvelope, UnknownTypedTransaction};

pub use alloy_consensus::{AnyHeader, AnyReceiptEnvelope};
pub use alloy_consensus_any::{AnyHeader, AnyReceiptEnvelope};

use crate::Network;
use alloy_rpc_types_eth::{AnyTransactionReceipt, Block, Transaction, TransactionRequest};
pub use alloy_rpc_types_any::{AnyRpcHeader, AnyTransactionReceipt};
use alloy_rpc_types_eth::{Block, Transaction, TransactionRequest};
use alloy_serde::WithOtherFields;

/// A catch-all header type for handling headers on multiple networks.
pub type AnyRpcHeader = alloy_rpc_types_eth::Header<alloy_consensus::AnyHeader>;

/// A catch-all block type for handling blocks on multiple networks.
pub type AnyRpcBlock =
WithOtherFields<Block<WithOtherFields<Transaction<AnyTxEnvelope>>, AnyRpcHeader>>;
Expand Down Expand Up @@ -62,9 +60,9 @@ impl Network for AnyNetwork {

type UnsignedTx = AnyTypedTransaction;

type ReceiptEnvelope = alloy_consensus::AnyReceiptEnvelope;
type ReceiptEnvelope = AnyReceiptEnvelope;

type Header = alloy_consensus::AnyHeader;
type Header = AnyHeader;

type TransactionRequest = WithOtherFields<TransactionRequest>;

Expand Down
3 changes: 2 additions & 1 deletion crates/network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ pub use ethereum::{Ethereum, EthereumWallet};
mod any;
pub use any::{
AnyHeader, AnyNetwork, AnyReceiptEnvelope, AnyRpcBlock, AnyRpcHeader, AnyRpcTransaction,
AnyTxEnvelope, AnyTxType, AnyTypedTransaction, UnknownTxEnvelope, UnknownTypedTransaction,
AnyTransactionReceipt, AnyTxEnvelope, AnyTxType, AnyTypedTransaction, UnknownTxEnvelope,
UnknownTypedTransaction,
};

pub use alloy_eips::eip2718;
Expand Down
30 changes: 30 additions & 0 deletions crates/rpc-types-any/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "alloy-rpc-types-any"
description = "Types for any network"

version.workspace = true
edition.workspace = true
rust-version.workspace = true
authors.workspace = true
license.workspace = true
homepage.workspace = true
repository.workspace = true
exclude.workspace = true

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[lints]
workspace = true

[dependencies]
alloy-consensus-any = { workspace = true, features = ["serde"] }
alloy-rpc-types-eth.workspace = true
alloy-serde.workspace = true

[dev-dependencies]
alloy-primitives.workspace = true

serde.workspace = true
serde_json.workspace = true
3 changes: 3 additions & 0 deletions crates/rpc-types-any/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# alloy-rpc-types-any

Types for any network.
2 changes: 2 additions & 0 deletions crates/rpc-types-any/src/block.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// A catch-all header type for handling headers on multiple networks.
pub type AnyRpcHeader = alloy_rpc_types_eth::Header<alloy_consensus_any::AnyHeader>;
13 changes: 13 additions & 0 deletions crates/rpc-types-any/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#![doc = include_str!("../README.md")]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/alloy.jpg",
html_favicon_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/favicon.ico"
)]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

mod transaction;
pub use transaction::AnyTransactionReceipt;

mod block;
pub use block::AnyRpcHeader;
2 changes: 2 additions & 0 deletions crates/rpc-types-any/src/transaction/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod receipt;
pub use receipt::AnyTransactionReceipt;
Loading

0 comments on commit 30ee13f

Please sign in to comment.