mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
80 lines
2.6 KiB
Rust
80 lines
2.6 KiB
Rust
//! Ethereum specific engine API types and impls.
|
|
|
|
#![doc(
|
|
html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png",
|
|
html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256",
|
|
issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/"
|
|
)]
|
|
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
|
|
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
|
|
|
|
mod payload;
|
|
use std::sync::Arc;
|
|
|
|
pub use payload::{EthBuiltPayload, EthPayloadBuilderAttributes};
|
|
use reth_chainspec::ChainSpec;
|
|
use reth_engine_primitives::{EngineTypes, EngineValidator};
|
|
use reth_payload_primitives::{
|
|
validate_version_specific_fields, EngineApiMessageVersion, EngineObjectValidationError,
|
|
PayloadOrAttributes, PayloadTypes,
|
|
};
|
|
pub use reth_rpc_types::{
|
|
engine::{
|
|
ExecutionPayloadEnvelopeV2, ExecutionPayloadEnvelopeV3, ExecutionPayloadEnvelopeV4,
|
|
PayloadAttributes as EthPayloadAttributes,
|
|
},
|
|
ExecutionPayloadV1,
|
|
};
|
|
|
|
/// The types used in the default mainnet ethereum beacon consensus engine.
|
|
#[derive(Debug, Default, Clone, serde::Deserialize, serde::Serialize)]
|
|
#[non_exhaustive]
|
|
pub struct EthEngineTypes;
|
|
|
|
impl PayloadTypes for EthEngineTypes {
|
|
type BuiltPayload = EthBuiltPayload;
|
|
type PayloadAttributes = EthPayloadAttributes;
|
|
type PayloadBuilderAttributes = EthPayloadBuilderAttributes;
|
|
}
|
|
|
|
impl EngineTypes for EthEngineTypes {
|
|
type ExecutionPayloadV1 = ExecutionPayloadV1;
|
|
type ExecutionPayloadV2 = ExecutionPayloadEnvelopeV2;
|
|
type ExecutionPayloadV3 = ExecutionPayloadEnvelopeV3;
|
|
type ExecutionPayloadV4 = ExecutionPayloadEnvelopeV4;
|
|
}
|
|
|
|
/// Validator for the ethereum engine API.
|
|
#[derive(Debug, Clone)]
|
|
pub struct EthereumEngineValidator {
|
|
chain_spec: Arc<ChainSpec>,
|
|
}
|
|
|
|
impl EthereumEngineValidator {
|
|
/// Instantiates a new validator.
|
|
pub const fn new(chain_spec: Arc<ChainSpec>) -> Self {
|
|
Self { chain_spec }
|
|
}
|
|
}
|
|
|
|
impl<Types> EngineValidator<Types> for EthereumEngineValidator
|
|
where
|
|
Types: EngineTypes<PayloadAttributes = EthPayloadAttributes>,
|
|
{
|
|
fn validate_version_specific_fields(
|
|
&self,
|
|
version: EngineApiMessageVersion,
|
|
payload_or_attrs: PayloadOrAttributes<'_, EthPayloadAttributes>,
|
|
) -> Result<(), EngineObjectValidationError> {
|
|
validate_version_specific_fields(&self.chain_spec, version, payload_or_attrs)
|
|
}
|
|
|
|
fn ensure_well_formed_attributes(
|
|
&self,
|
|
version: EngineApiMessageVersion,
|
|
attributes: &EthPayloadAttributes,
|
|
) -> Result<(), EngineObjectValidationError> {
|
|
validate_version_specific_fields(&self.chain_spec, version, attributes.into())
|
|
}
|
|
}
|