1use structopt::StructOpt;
20use url::Url;
21
22#[derive(Clone)]
23pub struct RpcSettings {
24 pub listen: Url,
25 pub disabled_methods: Vec<String>,
26}
27
28impl RpcSettings {
29 pub fn is_method_disabled(&self, method: &String) -> bool {
30 self.disabled_methods.contains(method)
31 }
32 pub fn use_http(&self) -> bool {
33 self.listen.scheme().starts_with("http+")
34 }
35}
36
37impl Default for RpcSettings {
38 fn default() -> Self {
39 Self { listen: Url::parse("tcp://127.0.0.1:22222").unwrap(), disabled_methods: vec![] }
40 }
41}
42
43#[derive(Clone, Debug, serde::Deserialize, structopt::StructOpt, structopt_toml::StructOptToml)]
45#[structopt()]
46#[serde(rename = "rpc")]
47pub struct RpcSettingsOpt {
48 #[structopt(long, default_value = "tcp://127.0.0.1:22222")]
50 pub rpc_listen: Url,
51
52 #[structopt(long, use_delimiter = true)]
54 pub rpc_disabled_methods: Option<Vec<String>>,
55}
56
57impl From<RpcSettingsOpt> for RpcSettings {
58 fn from(opt: RpcSettingsOpt) -> Self {
59 Self {
60 listen: opt.rpc_listen,
61 disabled_methods: opt.rpc_disabled_methods.unwrap_or_default(),
62 }
63 }
64}