kona_rpc/config.rs
1//! Contains the RPC Configuration.
2
3use std::{net::SocketAddr, path::PathBuf};
4
5/// The RPC configuration.
6#[derive(Debug, Clone)]
7pub struct RpcBuilder {
8 /// Prevent the rpc server from being restarted.
9 pub no_restart: bool,
10 /// The RPC socket address.
11 pub socket: SocketAddr,
12 /// Enable the admin API.
13 pub enable_admin: bool,
14 /// File path used to persist state changes made via the admin API so they persist across
15 /// restarts.
16 pub admin_persistence: Option<PathBuf>,
17 /// Enable the websocket rpc server
18 pub ws_enabled: bool,
19 /// Enable development RPC endpoints
20 pub dev_enabled: bool,
21}
22
23impl RpcBuilder {
24 /// Returns whether WebSocket RPC endpoint is enabled
25 pub const fn ws_enabled(&self) -> bool {
26 self.ws_enabled
27 }
28
29 /// Returns whether development RPC endpoints are enabled
30 pub const fn dev_enabled(&self) -> bool {
31 self.dev_enabled
32 }
33
34 /// Returns the socket address of the [`RpcBuilder`].
35 pub const fn socket(&self) -> SocketAddr {
36 self.socket
37 }
38
39 /// Returns the number of times the RPC server will attempt to restart if it stops.
40 pub const fn restart_count(&self) -> u32 {
41 if self.no_restart { 0 } else { 3 }
42 }
43
44 /// Sets the given [`SocketAddr`] on the [`RpcBuilder`].
45 pub fn set_addr(self, addr: SocketAddr) -> Self {
46 Self { socket: addr, ..self }
47 }
48}