redgold_schema/
config_data.rs

1use crate::conf::local_stored_state::{AccountKeySource, LocalStoredState};
2use serde::{Deserialize, Serialize};
3
4#[derive(Clone, Serialize, Deserialize, Debug, Default, Eq, PartialEq)]
5#[serde(default)] // This allows fields to be omitted in TOML
6pub struct DebugSettings {
7    pub use_e2e_external_resource_mocks: Option<bool>,
8    pub test: Option<String>,
9    // dev mode
10    pub develop: Option<bool>,
11    // main developer
12    pub developer: Option<bool>,
13    pub id: Option<i32>,
14    pub genesis: Option<bool>,
15    pub enable_live_e2e: Option<bool>,
16    pub grafana_writer: Option<bool>,
17    pub live_e2e_interval_seconds: Option<i64>,
18    pub bypass_seed_enrichment: Option<bool>,
19    pub bypass_download: Option<bool>,
20    // CI / Debug words
21    pub words: Option<String>
22}
23
24#[derive(Clone, Serialize, Deserialize, Debug, Default, Eq, PartialEq)]
25#[serde(default)] // This allows fields to be omitted in TOML
26pub struct PartyConfigData {
27    // Enable multiparty support, requires API keys and additional setup for oracle pricing info.
28    pub enable: Option<bool>,
29    pub order_cutoff_delay_time: Option<i64>,
30    pub poll_interval: Option<i64>,
31    pub peer_timeout_seconds: Option<i64>,
32    pub gg20_peer_timeout_seconds: Option<i64>,
33    pub party_config: Option<NodePartyConfig>,
34}
35
36#[derive(Clone, Serialize, Deserialize, Debug, Default, Eq, PartialEq)]
37#[serde(default)]
38pub struct PortfolioFulfillmentConfigData {
39    pub stake_control_address: Option<String>
40}
41
42#[derive(Clone, Serialize, Deserialize, Debug, Default, Eq, PartialEq)]
43#[serde(default)]
44pub struct ServiceIntervals {
45    pub portfolio_fulfillment_agent_seconds: Option<u64>
46}
47
48#[derive(Clone, Serialize, Deserialize, Debug, Default, Eq, PartialEq)]
49#[serde(default)]
50pub struct DaqConfig {
51    pub poll_duration_seconds: Option<i64>
52}
53
54#[derive(Clone, Serialize, Deserialize, Debug, Default, Eq, PartialEq)]
55#[serde(default)]
56pub struct NodeData {
57    pub words: Option<String>,
58    pub peer_id: Option<String>,
59    pub network: Option<String>,
60    pub disable_control_api: Option<bool>,
61    pub nat_traversal_required: Option<bool>,
62    pub udp_keepalive_seconds: Option<u64>,
63    pub service_intervals: Option<ServiceIntervals>,
64    pub server_index: Option<i64>,
65    pub peer_id_index: Option<i64>,
66    pub port_offset: Option<i64>,
67    // Doesn't participate in any consensus operations, only watches the network for live data
68    pub watch_only_node: Option<bool>,
69    // Warning, you must have a LOT of disk space available / S3 for this to work
70    pub archival_mode: Option<bool>,
71    pub name: Option<String>,
72    pub ip: Option<String>,
73    pub http_client_proxy: Option<String>,
74    pub udp_serve_disabled: Option<bool>,
75    pub allowed_http_proxy_origins: Option<Vec<String>>,
76    // pub daq: Option<DaqConfig>
77}
78
79#[derive(Clone, Serialize, Deserialize, Debug, Default, Eq, PartialEq)]
80#[serde(default)]
81pub struct SecureData {
82    pub salt: Option<String>,
83    pub session_salt: Option<String>,
84    pub session_hashed_password: Option<String>,
85    pub config: Option<String>,
86    pub path: Option<String>,
87    pub usb_paths: Option<Vec<String>>,
88    pub capture_device_name: Option<String>
89}
90
91
92#[derive(Clone, Serialize, Deserialize, Debug, Eq, PartialEq, Default)]
93#[serde(default)] // This allows fields to be omitted in TOML
94pub struct RpcUrl {
95    pub currency: SupportedCurrency,
96    pub url: String,
97    pub network: String,
98    pub wallet_only: Option<bool>,
99    pub authentication: Option<String>,
100    pub file_path: Option<String>,
101    pub ws_only: Option<bool>,
102    pub ssh_host: Option<String>
103}
104
105#[derive(Clone, Serialize, Deserialize, Debug, Eq, PartialEq, Default)]
106#[serde(default)] // This allows fields to be omitted in TOML
107pub struct ExternalResources {
108    pub s3_backup_bucket: Option<String>,
109    pub rpcs: Option<Vec<RpcUrl>>,
110}
111
112
113#[derive(Clone, Serialize, Deserialize, Debug, Eq, PartialEq, Default)]
114#[serde(default)] // This allows fields to be omitted in TOML
115pub struct Keys {
116    pub words: Option<String>,
117    pub aws_access: Option<String>,
118    pub aws_secret: Option<String>,
119    pub etherscan: Option<String>,
120    pub recaptcha: Option<String>,
121}
122
123
124#[derive(Clone, Serialize, Deserialize, Debug, Eq, PartialEq, Default)]
125#[serde(default)] // This allows fields to be omitted in TOML
126pub struct EmailSettings {
127    pub from: Option<String>,
128    pub to: Option<String>,
129}
130
131
132// TODO: Consider should this be used as a global arg?
133#[derive(Clone, Serialize, Deserialize, Debug, Eq, PartialEq, Default)]
134#[serde(default)] // This allows fields to be omitted in TOML
135pub struct CliSettings {
136    pub cold: Option<bool>,
137    pub airgap: Option<bool>,
138    pub account: Option<String>,
139    pub currency: Option<String>,
140    pub path: Option<String>,
141    pub verbose: Option<bool>,
142    pub quiet: Option<bool>,
143    pub passphrase: Option<bool>,
144    pub interactive: Option<bool>,
145    pub non_interactive: Option<bool>
146}
147
148#[derive(Clone, Serialize, Deserialize, Debug, Eq, PartialEq, Default)]
149#[serde(default)] // This allows fields to be omitted in TOML
150pub struct TrustRatingLabelUserInput {
151    pub peer_id: String,
152    pub trust_data: Vec<TrustData>
153}
154
155impl TrustRatingLabelUserInput {
156    pub fn to_trust_rating_label(&self) -> RgResult<TrustRatingLabel> {
157        Ok(TrustRatingLabel {
158            peer_id: Some(PeerId::from_hex(&self.peer_id)?),
159            trust_data: self.trust_data.clone(),
160        })
161    }
162}
163
164// Migrate node_config stuff here
165#[derive(Clone, Serialize, Deserialize, Debug, Eq, PartialEq)]
166#[serde(default)] // This allows fields to be omitted in TOML
167pub struct ConfigData {
168    pub network: Option<String>,
169    pub home: Option<String>,
170    pub config: Option<String>,
171    pub data: Option<String>,
172    pub bulk: Option<String>,
173    pub node: Option<NodeData>,
174    pub party: Option<PartyConfigData>,
175    pub debug: Option<DebugSettings>,
176    pub local: Option<LocalStoredState>,
177    pub portfolio: Option<PortfolioFulfillmentConfigData>,
178    pub secure: Option<SecureData>,
179    pub offline: Option<bool>,
180    pub external: Option<ExternalResources>,
181    pub keys: Option<Keys>,
182    pub email: Option<EmailSettings>,
183    pub cli: Option<CliSettings>
184}
185
186impl ConfigData {
187
188    pub fn development_mode(&self) -> bool {
189        self.debug.as_ref().and_then(|x| x.develop).unwrap_or(false)
190    }
191
192    #[allow(deprecated)]
193    pub fn servers_old(&self) -> Vec<ServerOldFormat> {
194        self.local.as_ref()
195            .and_then(|x|
196                          x.deploy.as_ref()
197                              .map(|x| x.as_old_servers())
198                              .or(x.servers.clone())
199            ).unwrap_or_default()
200    }
201
202    #[allow(deprecated)]
203    pub fn generate_user_sample_config() -> Self {
204        Self {
205            network: Some("main".to_string()),
206            home: Some("/home/user".to_string()),
207            config: Some("/home/user/.rg/config.toml".to_string()),
208            data: Some("/home/user/.rg".to_string()),
209            bulk: Some("/home/user/mnt/.rg/".to_string()),
210            node: Some(NodeData {
211                words: Some("abuse lock pledge crowd pair become ridge alone target viable black plate ripple sad tape victory blood river gloom air crash invite volcano release".to_string()),
212                peer_id: Some("enter_your_peer_id_here_or_blank_to_generate_or_use_the_deploy_script".to_string()),
213                network: Some("main".to_string()),
214                disable_control_api: Some(false),
215                nat_traversal_required: Some(false),
216                udp_keepalive_seconds: None,
217                service_intervals: None,
218                server_index: Some(0),
219                peer_id_index: Some(0),
220                port_offset: Some(16180),
221                watch_only_node: Some(false),
222                archival_mode: Some(false),
223                name: Some("your_node_name_if_set_manually_instead_of_through_deployment".to_string()),
224                ip: Some("your_external_ip_goes_here".to_string()),
225                http_client_proxy: None,
226                udp_serve_disabled: Some(false),
227                allowed_http_proxy_origins: None,
228                // daq: None,
229            }),
230            party: Some(PartyConfigData {
231                enable: Some(false),
232                order_cutoff_delay_time: None,
233                poll_interval: None,
234                peer_timeout_seconds: None,
235                gg20_peer_timeout_seconds: None,
236                party_config: None,
237            }),
238            debug: None,
239            local: Some(LocalStoredState {
240                deploy: Some(Deployment{
241                    servers: Some(vec![ServerData{
242                        ssh_host: Some("your_ssh_host".to_string()),
243                        ssh_user: Some("root".to_string()),
244                        is_localhost: Some(false),
245                        external_ipv4: Some("your_ssh_machines_external_ip_here".to_string()),
246                        external_hostname: Some("only_necessary_if_using_dns".to_string()),
247                        instances: Some(vec![
248                            NodeInstance {
249                                name: Some("your_node_name".to_string()),
250                                index: Some(0),
251                                peer_id_index: Some(0),
252                                network_environment: Some("main".to_string()),
253                                host_port_offset: None,
254                                docker_swarm_proxy: None,
255                                keys: None,
256                                reward_address: None,
257                                use_id_ds_prefix: None,
258                                party_config: None,
259                                rpc_overrides: None,
260                            }
261                        ]
262                        ),
263                        deploy_metrics_instance: Some(true),
264                        ssh_jump_host: None,
265                    }]),
266                    docker_swarm_proxies: None,
267                    default_params: Some(DeploymentDefaultParams{
268                        reward_address: Some("your_cold_reward_address_here".to_string()),
269                        keys: None,
270                        network_environment: None,
271                    }),
272                }),
273                servers: None,
274                keys: Some(
275                    vec![
276                        AccountKeySource {
277                            name: "your_xpub_name".to_string(),
278                            derivation_path: "some_derivation_path".to_string(),
279                            xpub: "your_xpub_here".to_string(),
280                            hot_offset: None,
281                            key_name_source: None,
282                            device_id: None,
283                            key_reference_source: None,
284                            key_nickname_source: None,
285                            request_type: None,
286                            skip_persist: None,
287                            preferred_address: None,
288                            all_address: None,
289                            public_key: None,
290                        }
291                    ]
292                ),
293                // TODO: Add a user input type for trust data to avoid direct conversions
294                trust: None,
295                // trust: Some(
296                //     vec![
297                //         ServerTrustRatingLabels {
298                //             peer_id_index: 0,
299                //             labels: vec![
300                //                 TrustRatingLabelUserInput {
301                //                     peer_id: "other_peer_id".to_string(),
302                //                     trust_data: vec![
303                //                         TrustData{
304                //                             label_rating: Some(600),
305                //                             confidence: Some(800),
306                //                             hardness: Some(50),
307                //                             data: None,
308                //                             allow_model_override: true,
309                //                             rating_type: Some(RatingType::SecurityRating as i32),
310                //                         }
311                //                     ],
312                //                 }
313                //             ],
314                //             environment: Some("main".to_string()),
315                //         }
316                //     ]
317                // ),
318                saved_addresses: None,
319                contacts: None,
320                watched_address: None,
321                email_alert_config: None,
322                identities: None,
323                mnemonics: None,
324                private_keys: None,
325                internal_stored_data: None,
326            }),
327            portfolio: None,
328            secure: None,
329            offline: None,
330            external: None,
331            keys: None,
332            email: None,
333            cli: None,
334        }
335    }
336}
337
338use crate::conf::server_config::{Deployment, DeploymentDefaultParams, NodeInstance, NodePartyConfig, ServerData};
339use crate::proto_serde::ProtoSerde;
340use crate::servers::ServerOldFormat;
341use crate::structs::{PeerId, SupportedCurrency, TrustData, TrustRatingLabel};
342use crate::RgResult;
343use std::env;
344
345fn get_home_dir() -> Option<String> {
346    env::var("HOME").or_else(|_| env::var("USERPROFILE")).ok()
347}
348
349impl Default for ConfigData {
350    fn default() -> Self {
351        Self {
352            network: None,
353            home: get_home_dir(),
354            config: None,
355            data: None,
356            bulk: None,
357            node: None,
358            party: None,
359            debug: None,
360            local: Default::default(),
361            portfolio: Default::default(),
362            secure: Default::default(),
363            offline: None,
364            external: None,
365            keys: None,
366            email: None,
367            cli: None
368        }
369    }
370}