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