Skip to content

Commit

Permalink
gorc: config can leverage defaults better; print-config can show your…
Browse files Browse the repository at this point in the history
… actual config or defaults (#136)
  • Loading branch information
levicook authored Aug 10, 2021
1 parent 1395608 commit f058031
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
25 changes: 21 additions & 4 deletions orchestrator/gorc/src/commands/print_config.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
use abscissa_core::{Runnable, Command,Options};
use crate::config::GorcConfig;
use crate::{application::APP, prelude::*};
use abscissa_core::{Command, Options, Runnable};

#[derive(Command, Debug, Default, Options)]
pub struct PrintConfigCmd {}
pub struct PrintConfigCmd {
#[options(help = "should default config")]
show_default: bool,
}

impl Runnable for PrintConfigCmd {
fn run(&self) {
let config = crate::config::GorcConfig::default();
let config = if self.show_default {
GorcConfig::default()
} else {
let config = APP.config();
GorcConfig {
keystore: config.keystore.to_owned(),
gravity: config.gravity.to_owned(),
ethereum: config.ethereum.to_owned(),
cosmos: config.cosmos.to_owned(),
metrics: config.metrics.to_owned(),
}
};

print!("{}", toml::to_string(&config).unwrap());
}
}
}
14 changes: 7 additions & 7 deletions orchestrator/gorc/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use signatory::FsKeyStore;
use std::path::Path;

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
#[serde(default, deny_unknown_fields)]
pub struct GorcConfig {
pub keystore: String,
pub gravity: GravitySection,
Expand Down Expand Up @@ -46,7 +46,7 @@ impl Default for GorcConfig {
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
#[serde(default, deny_unknown_fields)]
pub struct GravitySection {
pub contract: String,
pub fees_denom: String,
Expand All @@ -55,14 +55,14 @@ pub struct GravitySection {
impl Default for GravitySection {
fn default() -> Self {
Self {
contract: "0x6b175474e89094c44da98b954eedeac495271d0f".to_owned(),
contract: "0x0000000000000000000000000000000000000000".to_owned(),
fees_denom: "stake".to_owned(),
}
}
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
#[serde(default, deny_unknown_fields)]
pub struct EthereumSection {
pub key_derivation_path: String,
pub rpc: String,
Expand All @@ -78,7 +78,7 @@ impl Default for EthereumSection {
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
#[serde(default, deny_unknown_fields)]
pub struct CosmosSection {
pub key_derivation_path: String,
pub grpc: String,
Expand All @@ -98,7 +98,7 @@ impl Default for CosmosSection {
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
#[serde(default, deny_unknown_fields)]
pub struct GasPrice {
pub amount: f64,
pub denom: String,
Expand All @@ -120,7 +120,7 @@ impl GasPrice {
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
#[serde(default, deny_unknown_fields)]
pub struct MetricsSection {
pub listen_addr: String,
pub listen_port: u16,
Expand Down

0 comments on commit f058031

Please sign in to comment.