Skip to main content

ckb_app_config/configs/
rpc.rs

1use ckb_jsonrpc_types::Script;
2use serde::{Deserialize, Serialize};
3
4/// RPC modules.
5#[derive(Clone, Debug, Copy, Eq, PartialEq, Serialize, Deserialize)]
6#[allow(missing_docs)]
7pub enum Module {
8    Net,
9    Chain,
10    Miner,
11    Pool,
12    Experiment,
13    Stats,
14    IntegrationTest,
15    Alert,
16    Subscription,
17    Debug,
18    Indexer,
19    RichIndexer,
20    Terminal,
21}
22
23/// RPC config options.
24#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Eq)]
25#[serde(deny_unknown_fields)]
26pub struct Config {
27    /// RPC server listen addresses.
28    pub listen_address: String,
29    /// RPC TCP server listen addresses.
30    ///
31    /// Only TCP and WS are supported to subscribe events via the Subscription RPC module.
32    #[serde(default)]
33    pub tcp_listen_address: Option<String>,
34    /// RPC WS server listen addresses.
35    ///
36    /// Only TCP and WS are supported to subscribe events via the Subscription RPC module.
37    #[serde(default)]
38    pub ws_listen_address: Option<String>,
39    /// Max request body size in bytes.
40    pub max_request_body_size: usize,
41    /// Number of RPC worker threads.
42    pub threads: Option<usize>,
43    /// Number of RPC batch limit.
44    pub rpc_batch_limit: Option<usize>,
45    /// Enabled RPC modules.
46    pub modules: Vec<Module>,
47    /// Rejects txs with scripts that might trigger known bugs
48    #[serde(default)]
49    pub reject_ill_transactions: bool,
50    /// Whether enable deprecated RPC methods.
51    ///
52    /// Deprecated RPC methods are disabled by default.
53    #[serde(default)]
54    pub enable_deprecated_rpc: bool,
55    /// Customized extra well known lock scripts.
56    #[serde(default)]
57    pub extra_well_known_lock_scripts: Vec<Script>,
58    /// Customized extra well known type scripts.
59    #[serde(default)]
60    pub extra_well_known_type_scripts: Vec<Script>,
61}
62
63impl Config {
64    /// Checks whether the Net module is enabled.
65    pub fn net_enable(&self) -> bool {
66        self.modules.contains(&Module::Net)
67    }
68
69    /// Checks whether the Chain module is enabled.
70    pub fn chain_enable(&self) -> bool {
71        self.modules.contains(&Module::Chain)
72    }
73
74    /// Checks whether the Miner module is enabled.
75    pub fn miner_enable(&self) -> bool {
76        self.modules.contains(&Module::Miner)
77    }
78
79    /// Checks whether the Pool module is enabled.
80    pub fn pool_enable(&self) -> bool {
81        self.modules.contains(&Module::Pool)
82    }
83
84    /// Checks whether the Experiment module is enabled.
85    pub fn experiment_enable(&self) -> bool {
86        self.modules.contains(&Module::Experiment)
87    }
88
89    /// Checks whether the Stats module is enabled.
90    pub fn stats_enable(&self) -> bool {
91        self.modules.contains(&Module::Stats)
92    }
93
94    /// Checks whether the Subscription module is enabled.
95    pub fn subscription_enable(&self) -> bool {
96        self.modules.contains(&Module::Subscription)
97    }
98
99    /// Checks whether the IntegrationTest module is enabled.
100    pub fn integration_test_enable(&self) -> bool {
101        self.modules.contains(&Module::IntegrationTest)
102    }
103
104    /// Checks whether the Alert module is enabled.
105    pub fn alert_enable(&self) -> bool {
106        self.modules.contains(&Module::Alert)
107    }
108
109    /// Checks whether the Debug module is enabled.
110    pub fn debug_enable(&self) -> bool {
111        self.modules.contains(&Module::Debug)
112    }
113
114    /// Checks whether the Terminal module is enabled.
115    pub fn terminal_enable(&self) -> bool {
116        self.modules.contains(&Module::Terminal)
117    }
118
119    /// Checks whether the Indexer module is enabled.
120    pub fn indexer_enable(&self) -> bool {
121        self.modules.contains(&Module::Indexer)
122    }
123
124    /// Checks whether the Rich Indexer module is enabled.
125    pub fn rich_indexer_enable(&self) -> bool {
126        self.modules.contains(&Module::RichIndexer)
127    }
128}