1mod cfx;
2mod error;
3mod eth;
4mod id_provider;
5
6pub use cfx::{
7 CfxRpcModule, RpcModuleBuilder as CfxRpcModuleBuilder,
8 RpcModuleSelection as CfxRpcModuleSelection,
9 RpcServerConfig as CfxRpcServerConfig,
10 RpcServerHandle as CfxRpcServerHandle,
11 TransportRpcModuleConfig as CfxTransportRpcModuleConfig,
12 TransportRpcModules as CfxTransportRpcModules,
13};
14pub use eth::{
15 RpcModuleBuilder, RpcModuleSelection, RpcServerConfig,
16 TransportRpcModuleConfig,
17};
18
19use std::net::SocketAddr;
20
21use jsonrpsee::server::{AlreadyStoppedError, ServerHandle};
22
23#[derive(Clone, Debug)]
24#[must_use = "Server stops if dropped"]
25pub struct RpcServerHandle {
26 pub http_local_addr: Option<SocketAddr>,
27 pub ws_local_addr: Option<SocketAddr>,
28 pub http: Option<ServerHandle>,
29 pub ws: Option<ServerHandle>,
30}
31
32impl RpcServerHandle {
33 pub const fn http_local_addr(&self) -> Option<SocketAddr> {
34 self.http_local_addr
35 }
36
37 pub const fn ws_local_addr(&self) -> Option<SocketAddr> {
38 self.ws_local_addr
39 }
40
41 pub fn stop(self) -> Result<(), AlreadyStoppedError> {
42 if let Some(handle) = self.http {
43 handle.stop()?
44 }
45
46 if let Some(handle) = self.ws {
47 handle.stop()?
48 }
49
50 Ok(())
51 }
52
53 pub fn http_url(&self) -> Option<String> {
54 self.http_local_addr.map(|addr| format!("http://{addr}"))
55 }
56
57 pub fn ws_url(&self) -> Option<String> {
58 self.ws_local_addr.map(|addr| format!("ws://{addr}"))
59 }
60}