1use std::{fmt::Display, path::PathBuf};
2
3#[derive(Debug, Default)]
5pub struct RunOpts {
6 pub(crate) service_name: Option<String>,
7 pub(crate) db_type: DbType,
9 pub(crate) debug: bool,
14 pub(crate) snapshot: PathBuf,
16 pub(crate) keypair: Option<String>,
18 pub(crate) relayer: Option<String>,
20 pub(crate) ip: Option<std::net::IpAddr>,
22 pub(crate) port: Option<u16>,
24 pub(crate) peering_port: Option<u16>,
26 pub(crate) db_path: Option<PathBuf>,
29 pub(crate) utxo_validation: bool,
31 pub(crate) poa_instant: bool,
34 pub(crate) enable_p2p: bool,
36 pub(crate) bootstrap_nodes: Option<String>,
39 pub(crate) sync_header_batch_size: Option<u32>,
41 pub(crate) enable_relayer: bool,
43 pub(crate) relayer_listener: Option<String>,
45 pub(crate) relayer_da_deploy_height: Option<u32>,
47 pub(crate) relayer_log_page_size: Option<u32>,
50 pub(crate) sync_block_stream_buffer_size: Option<u32>,
52}
53
54#[derive(Debug)]
55pub enum DbType {
56 InMemory,
57 RocksDb,
58}
59
60impl Default for DbType {
61 fn default() -> Self {
64 Self::RocksDb
65 }
66}
67
68impl Display for DbType {
69 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
70 match self {
71 DbType::InMemory => write!(f, "in-memory"),
72 DbType::RocksDb => write!(f, "rocks-db"),
73 }
74 }
75}
76
77impl RunOpts {
78 pub fn generate_params(self) -> Vec<String> {
79 let mut params = vec![];
80 if let Some(service_name) = self.service_name {
81 params.push(format!("--service-name {service_name}"));
82 }
83 if self.debug {
84 params.push("--debug".to_string());
85 }
86 if let Some(keypair) = self.keypair {
87 params.push(format!("--keypair {keypair}"));
88 }
89 if let Some(relayer) = self.relayer {
90 params.push(format!("--relayer {relayer}"));
91 }
92 if let Some(ip) = self.ip {
93 params.push(format!("--ip {ip}"));
94 }
95 if let Some(port) = self.port {
96 params.push(format!("--port {port}"));
97 }
98 if let Some(peering_port) = self.peering_port {
99 params.push(format!("--peering-port {peering_port}"));
100 }
101 if let Some(db_path) = self.db_path {
102 params.push(format!("--db-path {}", db_path.display()));
103 }
104 params.push(format!("--snapshot {}", self.snapshot.display()));
105 params.push(format!("--db-type {}", self.db_type));
106 if self.utxo_validation {
107 params.push("--utxo-validation".to_string());
108 }
109 if self.poa_instant {
112 params.push("--poa-instant true".to_string());
113 } else {
114 params.push("--poa-instant false".to_string());
115 }
116 if self.enable_p2p {
117 params.push("--enable-p2p".to_string());
118 }
119 if let Some(node) = self.bootstrap_nodes {
120 params.push(format!("--bootstrap-nodes {node}"));
121 }
122 if let Some(sync_header_batch_size) = self.sync_header_batch_size {
123 params.push(format!("--sync-header-batch-size {sync_header_batch_size}"));
124 }
125 if self.enable_relayer {
126 params.push("--enable-relayer".to_string());
127 }
128 if let Some(relayer_listener) = self.relayer_listener {
129 params.push(format!(
130 "--relayer-v2-listening-contracts {}",
131 relayer_listener
132 ));
133 }
134 if let Some(da_deploy_height) = self.relayer_da_deploy_height {
135 params.push(format!("--relayer-da-deploy-height {da_deploy_height}"));
136 }
137 if let Some(log_page_size) = self.relayer_log_page_size {
138 params.push(format!("--relayer-log-page-size {log_page_size}"));
139 }
140 if let Some(sync_block) = self.sync_block_stream_buffer_size {
141 params.push(format!("--sync-block-stream-buffer-size {sync_block}"));
142 }
143 let params: Vec<String> = params
149 .iter()
150 .flat_map(|cmd| cmd.split_whitespace())
151 .map(|a| a.to_string())
152 .collect();
153 params
154 }
155}