Skip to content

Commit

Permalink
chore(deps): bump axum to 0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Nov 15, 2023
1 parent 7769cf0 commit f8f5977
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 61 deletions.
84 changes: 54 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions crates/anvil/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ foundry-utils.workspace = true
# evm support
bytes = "1.4.0"
ethers = { workspace = true, features = ["rustls", "ws", "ipc"] }
trie-db = { version = "0.23" }
hash-db = { version = "0.15" }
memory-db = { version = "0.29" }
trie-db = "0.23"
hash-db = "0.15"
memory-db = "0.29"
alloy-primitives = { workspace = true, features = ["serde"] }

# axum related
axum = { version = "0.5", features = ["ws"] }
axum = { version = "0.6", features = ["ws"] }
hyper = "0.14"
tower = "0.4"
tower-http = { version = "0.4", features = ["trace"] }
Expand Down Expand Up @@ -69,7 +69,7 @@ clap_complete = { version = "4", optional = true }
chrono.workspace = true
auto_impl = "1"
ctrlc = { version = "3", optional = true }
fdlimit = { version = "0.2", optional = true }
fdlimit = { version = "0.3", optional = true }
clap_complete_fig = "4"
ethereum-forkid = "0.12"

Expand Down
4 changes: 2 additions & 2 deletions crates/anvil/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ open-fastrlp = { version = "0.1.4", optional = true }
hash-db = { version = "0.15", default-features = false }
hash256-std-hasher = { version = "0.15", default-features = false }
triehash = { version = "0.8", default-features = false }
reference-trie = { version = "0.25" }
keccak-hasher = { version = "0.15" }
reference-trie = "0.25"
keccak-hasher = "0.15"

[dev-dependencies]
anvil-core = { path = ".", features = ["serde"] }
Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repository.workspace = true
anvil-rpc = { path = "../rpc" }

# axum related
axum = { version = "0.5", features = ["ws"] }
axum = { version = "0.6", features = ["ws"] }
hyper = "0.14"
tower-http = { version = "0.4", features = ["trace", "cors"] }

Expand Down
22 changes: 11 additions & 11 deletions crates/anvil/server/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ use anvil_rpc::{
response::{Response, RpcResponse},
};
use axum::{
extract::{rejection::JsonRejection, Extension},
extract::{rejection::JsonRejection, State},
Json,
};
use futures::{future, FutureExt};

/// Handles incoming JSON-RPC Request
pub async fn handle<Handler: RpcHandler>(
/// Handles incoming JSON-RPC Request.
// NOTE: `handler` must come first because the `request` extractor consumes the request body.
pub async fn handle<Http: RpcHandler, Ws>(
State((handler, _)): State<(Http, Ws)>,
request: Result<Json<Request>, JsonRejection>,
Extension(handler): Extension<Handler>,
) -> Json<Response> {
match request {
Json(match request {
Ok(Json(req)) => handle_request(req, handler)
.await
.unwrap_or_else(|| Response::error(RpcError::invalid_request())),
Err(err) => {
warn!(target: "rpc", ?err, "invalid request");
Response::error(RpcError::invalid_request()).into()
Response::error(RpcError::invalid_request())
}
Ok(req) => handle_request(req.0, handler)
.await
.unwrap_or_else(|| Response::error(RpcError::invalid_request()))
.into(),
}
})
}

/// Handle the JSON-RPC [Request]
Expand Down
10 changes: 4 additions & 6 deletions crates/anvil/server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use anvil_rpc::{
response::{ResponseResult, RpcResponse},
};
use axum::{
extract::Extension,
http::{header, HeaderValue, Method},
routing::{post, IntoMakeService},
Router, Server,
Expand Down Expand Up @@ -52,9 +51,8 @@ where
let ServerConfig { allow_origin, no_cors } = config;

let svc = Router::new()
.route("/", post(handler::handle::<Http>).get(ws::handle_ws::<Ws>))
.layer(Extension(http))
.layer(Extension(ws))
.route("/", post(handler::handle).get(ws::handle_ws))
.with_state((http, ws))
.layer(TraceLayer::new_for_http());

let svc = if no_cors {
Expand All @@ -81,8 +79,8 @@ where
let ServerConfig { allow_origin, no_cors } = config;

let svc = Router::new()
.route("/", post(handler::handle::<Http>))
.layer(Extension(http))
.route("/", post(handler::handle))
.with_state((http, ()))
.layer(TraceLayer::new_for_http());
let svc = if no_cors {
svc
Expand Down
11 changes: 5 additions & 6 deletions crates/anvil/server/src/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ use anvil_rpc::request::Request;
use axum::{
extract::{
ws::{Message, WebSocket},
WebSocketUpgrade,
State, WebSocketUpgrade,
},
response::IntoResponse,
Extension,
response::Response,
};
use futures::{ready, Sink, Stream};
use std::{
Expand All @@ -17,10 +16,10 @@ use std::{
/// Handles incoming Websocket upgrade
///
/// This is the entrypoint invoked by the axum server for a websocket request
pub async fn handle_ws<Handler: PubSubRpcHandler>(
pub async fn handle_ws<Http, Ws: PubSubRpcHandler>(
ws: WebSocketUpgrade,
Extension(handler): Extension<Handler>,
) -> impl IntoResponse {
State((_, handler)): State<(Http, Ws)>,
) -> Response {
ws.on_upgrade(|socket| PubSubConnection::new(SocketConn(socket), handler))
}

Expand Down

0 comments on commit f8f5977

Please sign in to comment.