fix: configure ipc server properly (#2922)

This commit is contained in:
Matthias Seitz
2023-05-31 16:34:08 +02:00
committed by GitHub
parent c4764d4f27
commit d0f235893f
3 changed files with 73 additions and 11 deletions

View File

@ -656,6 +656,21 @@ mod tests {
assert_eq!(response, msg);
}
#[tokio::test]
async fn test_ipc_modules() {
let endpoint = dummy_endpoint();
let server = Builder::default().build(&endpoint).unwrap();
let mut module = RpcModule::new(());
let msg = r#"{"admin":"1.0","debug":"1.0","engine":"1.0","eth":"1.0","ethash":"1.0","miner":"1.0","net":"1.0","rpc":"1.0","txpool":"1.0","web3":"1.0"}"#;
module.register_method("rpc_modules", move |_, _| msg).unwrap();
let handle = server.start(module).await.unwrap();
tokio::spawn(handle.stopped());
let client = IpcClientBuilder::default().build(endpoint).await.unwrap();
let response: String = client.request("rpc_modules", rpc_params![]).await.unwrap();
assert_eq!(response, msg);
}
#[tokio::test(flavor = "multi_thread")]
#[traced_test]
async fn test_rpc_subscription() {

View File

@ -415,6 +415,20 @@ impl RpcModuleSelection {
.into_selection()
}
/// Returns the [RpcModuleSelection::STANDARD_MODULES] as a selection.
pub fn standard_modules() -> Vec<RethRpcModule> {
RpcModuleSelection::try_from_selection(RpcModuleSelection::STANDARD_MODULES.iter().copied())
.expect("valid selection")
.into_selection()
}
/// All modules that are available by default on IPC.
///
/// By default all modules are available on IPC.
pub fn default_ipc_modules() -> Vec<RethRpcModule> {
Self::all_modules()
}
/// Creates a new [RpcModuleSelection::Selection] from the given items.
///
/// # Example
@ -1477,6 +1491,7 @@ impl RpcServer {
ws_local_addr: ws_http.ws_local_addr,
http: None,
ws: None,
ipc_endpoint: None,
ipc: None,
};
@ -1487,6 +1502,7 @@ impl RpcServer {
if let Some((server, module)) =
ipc_server.and_then(|server| ipc.map(|module| (server, module)))
{
handle.ipc_endpoint = Some(server.endpoint().path().to_string());
handle.ipc = Some(server.start(module).await?);
}
@ -1515,6 +1531,7 @@ pub struct RpcServerHandle {
ws_local_addr: Option<SocketAddr>,
http: Option<ServerHandle>,
ws: Option<ServerHandle>,
ipc_endpoint: Option<String>,
ipc: Option<ServerHandle>,
}
@ -1548,6 +1565,11 @@ impl RpcServerHandle {
Ok(())
}
/// Returns the endpoint of the launched IPC server, if any
pub fn ipc_endpoint(&self) -> Option<String> {
self.ipc_endpoint.clone()
}
/// Returns the url to the http server
pub fn http_url(&self) -> Option<String> {
self.http_local_addr.map(|addr| format!("http://{addr}"))