Skip to content

Commit

Permalink
feat: add scaffold impl of EthFilter API handler
Browse files Browse the repository at this point in the history
  • Loading branch information
leruaa committed Feb 10, 2023
1 parent a58cf8a commit bd33611
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 2 deletions.
68 changes: 68 additions & 0 deletions crates/rpc/rpc/src/eth/filter.rs
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 2 additions & 0 deletions crates/rpc/rpc/src/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion crates/rpc/rpc/src/eth/pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit bd33611

Please sign in to comment.