diff --git a/crates/settings/src/lib.rs b/crates/settings/src/lib.rs index 61d78260a..cd0dc6f36 100644 --- a/crates/settings/src/lib.rs +++ b/crates/settings/src/lib.rs @@ -13,6 +13,7 @@ pub mod orderbook; pub mod plot_source; pub mod remote; pub mod scenario; +pub mod sentry; pub mod subgraph; pub mod token; pub mod unit_test; diff --git a/crates/settings/src/sentry.rs b/crates/settings/src/sentry.rs new file mode 100644 index 000000000..bf068957c --- /dev/null +++ b/crates/settings/src/sentry.rs @@ -0,0 +1,24 @@ +use crate::yaml::{optional_string, YamlError, YamlParsableString}; +use std::sync::{Arc, RwLock}; +use strict_yaml_rust::StrictYaml; + +#[derive(Clone, Debug)] +pub struct Sentry; + +impl YamlParsableString for Sentry { + fn parse_from_yaml(_: Arc>) -> Result { + Err(YamlError::InvalidTraitFunction) + } + + fn parse_from_yaml_optional( + document: Arc>, + ) -> Result, YamlError> { + let document_read = document.read().map_err(|_| YamlError::ReadLockError)?; + + if let Some(value) = optional_string(&document_read, "sentry") { + Ok(Some(value)) + } else { + Ok(None) + } + } +} diff --git a/crates/settings/src/yaml/mod.rs b/crates/settings/src/yaml/mod.rs index e2cf8c247..0fb9d9f22 100644 --- a/crates/settings/src/yaml/mod.rs +++ b/crates/settings/src/yaml/mod.rs @@ -33,6 +33,10 @@ pub trait YamlParsableVector: Sized { pub trait YamlParsableString { fn parse_from_yaml(document: Arc>) -> Result; + + fn parse_from_yaml_optional( + document: Arc>, + ) -> Result, YamlError>; } #[derive(Debug, Error)] @@ -61,6 +65,8 @@ pub enum YamlError { ReadLockError, #[error("Document write lock error")] WriteLockError, + #[error("Invalid trait function")] + InvalidTraitFunction, #[error(transparent)] ParseNetworkConfigSourceError(#[from] ParseNetworkConfigSourceError), #[error(transparent)] diff --git a/crates/settings/src/yaml/orderbook.rs b/crates/settings/src/yaml/orderbook.rs index c61a4149c..4f45a5252 100644 --- a/crates/settings/src/yaml/orderbook.rs +++ b/crates/settings/src/yaml/orderbook.rs @@ -1,5 +1,7 @@ use super::*; -use crate::{metaboard::Metaboard, subgraph::Subgraph, Deployer, Network, Orderbook, Token}; +use crate::{ + metaboard::Metaboard, sentry::Sentry, subgraph::Subgraph, Deployer, Network, Orderbook, Token, +}; use std::sync::{Arc, RwLock}; use strict_yaml_rust::StrictYamlEmitter; @@ -78,6 +80,11 @@ impl OrderbookYaml { pub fn get_deployer(&self, key: &str) -> Result { Deployer::parse_from_yaml(self.document.clone(), key) } + + pub fn get_sentry(&self) -> Result { + let value = Sentry::parse_from_yaml_optional(self.document.clone())?; + Ok(value.map_or(false, |v| v == "true")) + } } #[cfg(test)] @@ -204,6 +211,8 @@ mod tests { Address::from_str("0x0000000000000000000000000000000000000002").unwrap() ); assert_eq!(deployer.network, network.into()); + + assert!(ob_yaml.get_sentry().unwrap()); } #[test]