diff --git a/crates/network/Cargo.toml b/crates/network/Cargo.toml index 369bc288f05..ea0ad0835c9 100644 --- a/crates/network/Cargo.toml +++ b/crates/network/Cargo.toml @@ -9,3 +9,4 @@ edition = "2021" alloy-json-rpc.workspace = true alloy-rlp.workspace = true alloy-transports.workspace = true +tower = "0.4.13" diff --git a/crates/network/src/lib.rs b/crates/network/src/lib.rs index 191be47cbfb..d6b365c36b4 100644 --- a/crates/network/src/lib.rs +++ b/crates/network/src/lib.rs @@ -10,42 +10,30 @@ pub trait Transaction: alloy_rlp::Encodable + alloy_rlp::Decodable + RpcObject { pub trait Eip1559Transaction: Transaction {} -// pub trait Middleware -// where -// ::Fut: Send, -// { -// type Transport: Transport; -// type Inner: Middleware; - -// fn client(&self) -> &RpcClient; - -// fn inner(&self) -> &Self::Inner; - -// fn send_transaction( -// &self, -// tx: &N::Transaction, -// ) -> RpcCall { -// self.inner().send_transaction(tx) -// } -// } - -// impl Middleware for RpcClient { -// type Transport = T; - -// type Inner = Self; - -// fn client(&self) -> &RpcClient { -// self -// } - -// fn inner(&self) -> &Self::Inner { -// panic!("called inner on RpcClient") -// } - -// fn send_transaction( -// &self, -// tx: &N::Transaction, -// ) -> RpcCall { -// self.prepare("eth_sendTransaction", tx) -// } -// } +pub trait Middleware { + type Inner: Middleware; + + fn client(&self) -> &RpcClient; + + fn inner(&self) -> &Self::Inner; + + fn send_transaction(&self, tx: &N::Transaction) -> RpcCall { + self.inner().send_transaction(tx) + } +} + +impl Middleware for RpcClient { + type Inner = Self; + + fn client(&self) -> &RpcClient { + self + } + + fn inner(&self) -> &Self::Inner { + panic!("called inner on RpcClient") + } + + fn send_transaction(&self, tx: &N::Transaction) -> RpcCall { + self.prepare("eth_sendTransaction", tx) + } +} diff --git a/crates/transports/src/lib.rs b/crates/transports/src/lib.rs index 1071a747650..8c3e4fda132 100644 --- a/crates/transports/src/lib.rs +++ b/crates/transports/src/lib.rs @@ -19,18 +19,3 @@ mod transports; pub use transports::{Http, Transport}; pub use alloy_json_rpc::RpcResult; - -#[cfg(test)] -mod test { - use tower::util::BoxCloneService; - - use super::*; - - fn box_clone_transport() -> BoxCloneService< - Box, - Box, - TransportError, - > { - BoxCloneService::new(Http::new("http://localhost:8545".parse().unwrap())) - } -}