mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore(sdk): add helper trait to node API to simplify type definition (#10616)
This commit is contained in:
@ -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
|
||||
|
||||
@ -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};
|
||||
|
||||
|
||||
58
crates/rpc/rpc-eth-api/src/node.rs
Normal file
58
crates/rpc/rpc-eth-api/src/node.rs
Normal 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)
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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};
|
||||
|
||||
Reference in New Issue
Block a user