feat: add scaffold impl of EthFilter API handler (#1270)

This commit is contained in:
Aurélien
2023-02-10 14:07:00 +01:00
committed by GitHub
parent 3a13a399da
commit 9a4df50a92
4 changed files with 72 additions and 2 deletions

View File

@ -0,0 +1,68 @@
use async_trait::async_trait;
use jsonrpsee::core::RpcResult;
use reth_primitives::{rpc::Filter, U256};
use reth_provider::BlockProvider;
use reth_rpc_api::EthFilterApiServer;
use reth_rpc_types::{FilterChanges, Index, Log};
use reth_transaction_pool::TransactionPool;
use std::sync::Arc;
/// `Eth` filter RPC implementation.
#[derive(Debug, Clone)]
pub struct EthFilter<Pool, Client> {
/// All nested fields bundled together.
inner: Arc<EthFilterInner<Pool, Client>>,
}
impl<Pool, Client> EthFilter<Pool, Client> {
/// Creates a new, shareable instance.
pub fn new(client: Arc<Client>, pool: Pool) -> Self {
let inner = EthFilterInner { client, pool };
Self { inner: Arc::new(inner) }
}
}
#[async_trait]
impl<Pool, Client> EthFilterApiServer for EthFilter<Pool, Client>
where
Pool: TransactionPool + 'static,
Client: BlockProvider + 'static,
{
fn new_filter(&self, _filter: Filter) -> RpcResult<U256> {
todo!()
}
fn new_block_filter(&self) -> RpcResult<U256> {
todo!()
}
fn new_pending_transaction_filter(&self) -> RpcResult<U256> {
todo!()
}
async fn filter_changes(&self, _index: Index) -> RpcResult<FilterChanges> {
todo!()
}
async fn filter_logs(&self, _index: Index) -> RpcResult<Vec<Log>> {
todo!()
}
fn uninstall_filter(&self, _index: Index) -> RpcResult<bool> {
todo!()
}
async fn logs(&self, _filter: Filter) -> RpcResult<Vec<Log>> {
todo!()
}
}
/// Container type `EthFilter`
#[derive(Debug)]
struct EthFilterInner<Pool, Client> {
/// The transaction pool.
pool: Pool,
/// The client that can interact with the chain.
client: Arc<Client>,
// TODO needs spawn access
}

View File

@ -2,8 +2,10 @@
mod api;
pub(crate) mod error;
mod filter;
mod pubsub;
mod signer;
pub use api::{EthApi, EthApiSpec};
pub use filter::EthFilter;
pub use pubsub::EthPubSub;

View File

@ -52,7 +52,7 @@ async fn handle_accepted<Pool, Client>(
) {
}
/// Container type `EthApi`
/// Container type `EthPubSub`
#[derive(Debug)]
struct EthPubSubInner<Pool, Client> {
/// The transaction pool.

View File

@ -23,7 +23,7 @@ mod web3;
pub use admin::AdminApi;
pub use debug::DebugApi;
pub use engine::EngineApi;
pub use eth::{EthApi, EthApiSpec, EthPubSub};
pub use eth::{EthApi, EthApiSpec, EthFilter, EthPubSub};
pub use layers::{AuthLayer, AuthValidator, JwtAuthValidator, JwtError, JwtSecret};
pub use net::NetApi;
pub use trace::TraceApi;