Skip to content

Commit 2bb910e

Browse files
committed
Add EmailAlarm config
1 parent 83e8a4d commit 2bb910e

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

codechain/config/mod.rs

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ pub struct Config {
4242
pub ws: Ws,
4343
pub snapshot: Snapshot,
4444
pub stratum: Stratum,
45+
#[serde(default)]
46+
pub email_alarm: EmailAlarm,
4547
}
4648

4749
impl Config {
@@ -54,6 +56,7 @@ impl Config {
5456
self.ws.merge(&other.ws);
5557
self.snapshot.merge(&other.snapshot);
5658
self.stratum.merge(&other.stratum);
59+
self.email_alarm.merge(&other.email_alarm);
5760
}
5861

5962
pub fn miner_options(&self) -> Result<MinerOptions, String> {
@@ -288,6 +291,15 @@ pub struct Stratum {
288291
pub port: Option<u16>,
289292
}
290293

294+
295+
#[derive(Deserialize)]
296+
#[serde(deny_unknown_fields)]
297+
pub struct EmailAlarm {
298+
pub disable: Option<bool>,
299+
pub to: Option<String>,
300+
pub sendgrid_key: Option<String>,
301+
}
302+
291303
impl Ipc {
292304
pub fn merge(&mut self, other: &Ipc) {
293305
if other.disable.is_some() {
@@ -691,6 +703,44 @@ impl Stratum {
691703
}
692704
}
693705

706+
impl EmailAlarm {
707+
pub fn merge(&mut self, other: &EmailAlarm) {
708+
if other.disable.is_some() {
709+
self.disable = other.disable;
710+
}
711+
if other.to.is_some() {
712+
self.to = other.to.clone();
713+
}
714+
if other.sendgrid_key.is_some() {
715+
self.sendgrid_key = other.sendgrid_key.clone();
716+
}
717+
}
718+
719+
pub fn overwrite_with(&mut self, matches: &clap::ArgMatches) -> Result<(), String> {
720+
if matches.is_present("no-email-alarm") {
721+
self.disable = Some(true);
722+
}
723+
if let Some(to) = matches.value_of("email-alarm-to") {
724+
self.to = Some(to.to_string());
725+
}
726+
if let Some(sendgrid_key) = matches.value_of("email-alarm-sendgrid-key") {
727+
self.sendgrid_key = Some(sendgrid_key.to_string());
728+
}
729+
730+
Ok(())
731+
}
732+
}
733+
734+
impl Default for EmailAlarm {
735+
fn default() -> Self {
736+
Self {
737+
disable: Some(true),
738+
to: None,
739+
sendgrid_key: None,
740+
}
741+
}
742+
}
743+
694744
#[cfg(not(debug_assertions))]
695745
pub fn read_preset_config() -> &'static str {
696746
let bytes = include_bytes!("presets/config.prod.toml");
@@ -724,6 +774,6 @@ pub fn load_config(matches: &clap::ArgMatches) -> Result<Config, String> {
724774
config.ws.overwrite_with(&matches)?;
725775
config.snapshot.overwrite_with(&matches)?;
726776
config.stratum.overwrite_with(&matches)?;
727-
777+
config.email_alarm.overwrite_with(&matches)?;
728778
Ok(config)
729779
}

0 commit comments

Comments
 (0)