Skip to content

chore: delete eth for now #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ incremental = false

[workspace.dependencies]
router = { path = "./crates/router" }
eth = { path = "./crates/eth" }
pubsub = { path = "./crates/pubsub" }

# alloy = { version = "0.9.2", features = ["json-rpc", "rpc-types"] }
Expand Down
19 changes: 0 additions & 19 deletions crates/eth/Cargo.toml

This file was deleted.

122 changes: 0 additions & 122 deletions crates/eth/src/lib.rs

This file was deleted.

10 changes: 6 additions & 4 deletions crates/router/src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,22 @@ impl From<mpsc::Sender<Box<RawValue>>> for HandlerCtx {

impl HandlerCtx {
/// Instantiate a new handler context.
pub fn new() -> Self {
Default::default()
pub const fn new() -> Self {
Self {
notifications: None,
}
}

/// Instantiation a new handler context with notifications enabled.
pub fn with_notifications(notifications: mpsc::Sender<Box<RawValue>>) -> Self {
pub const fn with_notifications(notifications: mpsc::Sender<Box<RawValue>>) -> Self {
Self {
notifications: Some(notifications),
}
}

/// Get a reference to the notification sender. This is used to
/// send notifications over pubsub transports.
pub fn notifications(&self) -> Option<&mpsc::Sender<Box<RawValue>>> {
pub const fn notifications(&self) -> Option<&mpsc::Sender<Box<RawValue>>> {
self.notifications.as_ref()
}
}
1 change: 1 addition & 0 deletions crates/router/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::borrow::Cow;
/// Errors that can occur when registering a method.
#[derive(Debug, Clone, thiserror::Error)]
pub enum RegistrationError {
/// Method name is already in use.
#[error("Method already registered: {0}")]
MethodAlreadyRegistered(Cow<'static, str>),
}
Expand Down
12 changes: 11 additions & 1 deletion crates/router/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,17 @@
//!
//! [`axum`]: https://docs.rs/axum/latest/axum/index.html
//! [`axum::Router`]: https://docs.rs/axum/latest/axum/routing/struct.Router.html

#![warn(
missing_copy_implementations,
missing_debug_implementations,
missing_docs,
unreachable_pub,
clippy::missing_const_for_fn,
rustdoc::all
)]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![deny(unused_must_use, rust_2018_idioms)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

#[macro_use]
Expand All @@ -32,7 +42,7 @@ pub use primitives::MethodId;

mod routes;
pub(crate) use routes::{BoxedIntoRoute, ErasedIntoRoute, Method};
pub use routes::{Handler, HandlerService, Route};
pub use routes::{Handler, HandlerArgs, HandlerService, MethodFuture, Route};

mod router;
pub use router::Router;
Expand Down
12 changes: 9 additions & 3 deletions crates/router/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,12 @@ where

MethodFuture::new(id, fut)
}

/// Nest this router into a new Axum router, with the specified path.
#[cfg(feature = "axum")]
pub fn into_axum(self, path: &str) -> axum::Router<S> {
axum::Router::new().route(path, axum::routing::post(self))
}
}

impl Router<()> {
Expand Down Expand Up @@ -393,7 +399,7 @@ impl<S> fmt::Debug for RouterInner<S> {

impl<S> RouterInner<S> {
/// Create a new, empty router.
pub fn new() -> Self {
pub(crate) fn new() -> Self {
Self {
routes: BTreeMap::new(),

Expand All @@ -410,7 +416,7 @@ impl<S> RouterInner<S> {
///
/// Note that the type parameter `S2` is NOT the state you are adding to the
/// router. It is additional state that must be added AFTER the state `S`.
pub fn with_state<S2>(self, state: &S) -> RouterInner<S2>
pub(crate) fn with_state<S2>(self, state: &S) -> RouterInner<S2>
where
S: Clone,
{
Expand Down Expand Up @@ -527,7 +533,7 @@ impl<S> RouterInner<S> {
///
/// Panic if the method name already exists in the router.
#[track_caller]
pub fn route_service<T>(self, method: impl Into<Cow<'static, str>>, service: T) -> Self
pub(crate) fn route_service<T>(self, method: impl Into<Cow<'static, str>>, service: T) -> Self
where
T: Service<
(HandlerCtx, Box<RawValue>),
Expand Down
6 changes: 2 additions & 4 deletions crates/router/src/routes/erased.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,13 @@ pub(crate) trait ErasedIntoRoute<S>: Send + Sync {
///
/// Similar to axum's [`BoxedIntoRoute`]
///
/// Currently this is a placeholder to enable future convenience functions.
///
/// [`BoxedIntoRoute`]: https://github.com/tokio-rs/axum/blob/18a99da0b0baf9eeef326b34525826ae0b5a1370/axum/src/boxed.rs#L12
pub(crate) struct BoxedIntoRoute<S>(pub(crate) Box<dyn ErasedIntoRoute<S>>);

#[allow(dead_code)]
impl<S> BoxedIntoRoute<S> {
/// Convert this into a [`Route`] with the given state.
pub fn into_route(self, state: S) -> Route {
pub(crate) fn into_route(self, state: S) -> Route {
self.0.into_route(state)
}
}
Expand Down Expand Up @@ -85,7 +83,7 @@ where
impl<H, S> MakeErasedHandler<H, S> {
/// Create a new [`MakeErasedHandler`] with the given handler and conversion
/// function.
pub fn from_handler<T>(handler: H) -> Self
pub(crate) fn from_handler<T>(handler: H) -> Self
where
H: Handler<T, S>,
T: Send + 'static,
Expand Down
6 changes: 4 additions & 2 deletions crates/router/src/routes/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct RouteFuture {

impl RouteFuture {
/// Create a new route future.
pub fn new(
pub const fn new(
inner: Oneshot<BoxCloneSyncService<HandlerArgs, ResponsePayload, Infallible>, HandlerArgs>,
) -> Self {
Self { inner }
Expand All @@ -44,6 +44,8 @@ impl Future for RouteFuture {
}
}

/// A future for a method, containing the request ID, and the inner future
/// which resolves to the response.
#[pin_project]
pub struct MethodFuture {
/// The request ID. Guaranteed to be `Some` until the future is completed.
Expand All @@ -55,7 +57,7 @@ pub struct MethodFuture {

impl MethodFuture {
/// Create a new method future.
pub fn new(id: Id, fut: RouteFuture) -> Self {
pub const fn new(id: Id, fut: RouteFuture) -> Self {
Self {
inner: fut,
id: Some(id),
Expand Down
9 changes: 7 additions & 2 deletions crates/router/src/routes/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ impl<S> Clone for Method<S> {

impl<S> Method<S> {
/// Call the method with the given state and request.
pub fn call_with_state(&self, ctx: HandlerCtx, req: Box<RawValue>, state: S) -> RouteFuture {
pub(crate) fn call_with_state(
&self,
ctx: HandlerCtx,
req: Box<RawValue>,
state: S,
) -> RouteFuture {
match self {
Self::Ready(route) => route.clone().oneshot_inner_owned(ctx, req),
Self::Needs(handler) => handler
Expand All @@ -40,7 +45,7 @@ where
S: Clone,
{
/// Add state to a method, converting
pub fn with_state<S2>(self, state: &S) -> Method<S2> {
pub(crate) fn with_state<S2>(self, state: &S) -> Method<S2> {
match self {
Self::Ready(route) => Method::Ready(route),
Self::Needs(handler) => Method::Ready(handler.0.into_route(state.clone())),
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/routes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub type HandlerArgs = (HandlerCtx, Box<RawValue>);
/// a JSON-RPC [`ResponsePayload`]. Routes SHOULD be infallible. I.e. any error
/// that occurs during the handling of a request should be represented as a
/// JSON-RPC error response, rather than having the service return an `Err`.
#[derive(Debug)]
pub struct Route(tower::util::BoxCloneSyncService<HandlerArgs, ResponsePayload, Infallible>);

impl Route {
Expand Down
Loading