-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
119 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/// Result alias | ||
pub type NodeResult<T> = Result<T, NodeError>; | ||
|
||
/// An error that can occur when launching a anvil instance | ||
#[derive(Debug, thiserror::Error)] | ||
pub enum NodeError { | ||
#[error(transparent)] | ||
Hyper(#[from] hyper::Error), | ||
#[error(transparent)] | ||
Io(#[from] std::io::Error), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,29 @@ | ||
//! Contains the code to launch an ethereum RPC-Server | ||
use crate::EthApi; | ||
use anvil_server::{AnvilServer, ServerConfig}; | ||
use handler::{HttpEthRpcHandler, WsEthRpcHandler}; | ||
use anvil_server::{ipc::IpcEndpoint, AnvilServer, ServerConfig}; | ||
use handler::{HttpEthRpcHandler, PubSubEthRpcHandler}; | ||
use std::net::SocketAddr; | ||
use tokio::{io, task::JoinHandle}; | ||
|
||
mod handler; | ||
|
||
pub mod error; | ||
|
||
/// Configures an [axum::Server] that handles [EthApi] related JSON-RPC calls via HTTP and WS | ||
pub fn serve(addr: SocketAddr, api: EthApi, config: ServerConfig) -> AnvilServer { | ||
let http = HttpEthRpcHandler::new(api.clone()); | ||
let ws = WsEthRpcHandler::new(api); | ||
let ws = PubSubEthRpcHandler::new(api); | ||
anvil_server::serve_http_ws(addr, config, http, ws) | ||
} | ||
|
||
/// Launches an ipc server at the given path in a new task | ||
pub fn spawn_ipc(api: EthApi, path: impl Into<String>) -> JoinHandle<io::Result<()>> { | ||
let path = path.into(); | ||
tokio::task::spawn(async move { | ||
let handler = PubSubEthRpcHandler::new(api); | ||
let ipc = IpcEndpoint::new(handler, path); | ||
ipc.listen().await; | ||
|
||
Ok(()) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters