chore(sdk): add helper trait to node API to simplify type definition (#10616)

This commit is contained in:
Emilia Hane
2024-10-26 18:55:26 +08:00
committed by GitHub
parent ac329bfce1
commit 44e4c47803
18 changed files with 105 additions and 61 deletions

View File

@ -30,6 +30,7 @@ reth-rpc-eth-types.workspace = true
reth-rpc-server-types.workspace = true
reth-network-api.workspace = true
reth-trie.workspace = true
reth-node-api.workspace = true
# ethereum
alloy-eips.workspace = true

View File

@ -16,6 +16,7 @@ pub mod bundle;
pub mod core;
pub mod filter;
pub mod helpers;
pub mod node;
pub mod pubsub;
pub mod types;
@ -25,6 +26,7 @@ pub use bundle::{EthBundleApiServer, EthCallBundleApiServer};
pub use core::{EthApiServer, FullEthApiServer};
pub use filter::EthFilterApiServer;
pub use helpers::error::{AsEthApiError, FromEthApiError, FromEvmError, IntoEthApiError};
pub use node::RpcNodeCore;
pub use pubsub::EthPubSubApiServer;
pub use types::{EthApiTypes, FullEthApiTypes, RpcBlock, RpcReceipt, RpcTransaction};

View File

@ -0,0 +1,58 @@
//! Helper trait for interfacing with [`FullNodeComponents`].
use reth_node_api::FullNodeComponents;
/// Helper trait to relax trait bounds on [`FullNodeComponents`].
///
/// Helpful when defining types that would otherwise have a generic `N: FullNodeComponents`. Using
/// `N: RpcNodeCore` instead, allows access to all the associated types on [`FullNodeComponents`]
/// that are used in RPC, but with more flexibility since they have no trait bounds (asides auto
/// traits).
pub trait RpcNodeCore: Clone {
/// The provider type used to interact with the node.
type Provider: Send + Sync + Clone + Unpin;
/// The transaction pool of the node.
type Pool: Send + Sync + Clone + Unpin;
/// The node's EVM configuration, defining settings for the Ethereum Virtual Machine.
type Evm: Send + Sync + Clone + Unpin;
/// Network API.
type Network: Send + Sync + Clone;
/// Returns the transaction pool of the node.
fn pool(&self) -> &Self::Pool;
/// Returns the node's evm config.
fn evm_config(&self) -> &Self::Evm;
/// Returns the handle to the network
fn network(&self) -> &Self::Network;
/// Returns the provider of the node.
fn provider(&self) -> &Self::Provider;
}
impl<T> RpcNodeCore for T
where
T: FullNodeComponents,
{
type Provider = T::Provider;
type Pool = T::Pool;
type Network = <T as FullNodeComponents>::Network;
type Evm = <T as FullNodeComponents>::Evm;
fn pool(&self) -> &Self::Pool {
FullNodeComponents::pool(self)
}
fn evm_config(&self) -> &Self::Evm {
FullNodeComponents::evm_config(self)
}
fn network(&self) -> &Self::Network {
FullNodeComponents::network(self)
}
fn provider(&self) -> &Self::Provider {
FullNodeComponents::provider(self)
}
}

View File

@ -31,7 +31,6 @@ reth-network-peers = { workspace = true, features = ["secp256k1"] }
reth-evm.workspace = true
reth-rpc-eth-types.workspace = true
reth-rpc-server-types.workspace = true
reth-node-api.workspace = true
reth-network-types.workspace = true
reth-trie.workspace = true

View File

@ -17,10 +17,11 @@ use alloy_rpc_types::{
use async_trait::async_trait;
use jsonrpsee::{core::RpcResult, server::IdProvider};
use reth_chainspec::ChainInfo;
use reth_node_api::EthApiTypes;
use reth_primitives::{Receipt, SealedBlockWithSenders, TransactionSignedEcRecovered};
use reth_provider::{BlockIdReader, BlockReader, EvmEnvProvider, ProviderError};
use reth_rpc_eth_api::{EthFilterApiServer, FullEthApiTypes, RpcTransaction, TransactionCompat};
use reth_rpc_eth_api::{
EthApiTypes, EthFilterApiServer, FullEthApiTypes, RpcTransaction, TransactionCompat,
};
use reth_rpc_eth_types::{
logs_utils::{self, append_matching_block_logs, ProviderOrBlock},
EthApiError, EthFilterConfig, EthStateCache, EthSubscriptionIdProvider,

View File

@ -15,4 +15,4 @@ pub use pubsub::EthPubSub;
pub use helpers::{signer::DevSigner, types::EthTxBuilder};
pub use reth_rpc_eth_api::EthApiServer;
pub use reth_rpc_eth_api::{EthApiServer, EthApiTypes, FullEthApiServer, RpcNodeCore};