Skip to content

Commit

Permalink
Merge pull request #1084 from rainlanguage/2024-12-16-ob-yaml-sentry
Browse files Browse the repository at this point in the history
Implementing sentry in OrderbookYaml
  • Loading branch information
hardyjosh authored Dec 19, 2024
2 parents 9be5363 + 391e35b commit 82c18af
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions crates/settings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 24 additions & 0 deletions crates/settings/src/sentry.rs
Original file line number Diff line number Diff line change
@@ -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<RwLock<StrictYaml>>) -> Result<String, YamlError> {
Err(YamlError::InvalidTraitFunction)
}

fn parse_from_yaml_optional(
document: Arc<RwLock<StrictYaml>>,
) -> Result<Option<String>, 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)
}
}
}
6 changes: 6 additions & 0 deletions crates/settings/src/yaml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ pub trait YamlParsableVector: Sized {

pub trait YamlParsableString {
fn parse_from_yaml(document: Arc<RwLock<StrictYaml>>) -> Result<String, YamlError>;

fn parse_from_yaml_optional(
document: Arc<RwLock<StrictYaml>>,
) -> Result<Option<String>, YamlError>;
}

#[derive(Debug, Error)]
Expand Down Expand Up @@ -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)]
Expand Down
11 changes: 10 additions & 1 deletion crates/settings/src/yaml/orderbook.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -78,6 +80,11 @@ impl OrderbookYaml {
pub fn get_deployer(&self, key: &str) -> Result<Deployer, YamlError> {
Deployer::parse_from_yaml(self.document.clone(), key)
}

pub fn get_sentry(&self) -> Result<bool, YamlError> {
let value = Sentry::parse_from_yaml_optional(self.document.clone())?;
Ok(value.map_or(false, |v| v == "true"))
}
}

#[cfg(test)]
Expand Down Expand Up @@ -204,6 +211,8 @@ mod tests {
Address::from_str("0x0000000000000000000000000000000000000002").unwrap()
);
assert_eq!(deployer.network, network.into());

assert!(ob_yaml.get_sentry().unwrap());
}

#[test]
Expand Down

0 comments on commit 82c18af

Please sign in to comment.