Skip to content

Commit

Permalink
refactor(market-data-feeder): Move out definitions out of binary pack…
Browse files Browse the repository at this point in the history
…age into library one.
  • Loading branch information
KirilMihaylov committed Aug 21, 2024
1 parent a27e897 commit ccafab8
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 32 deletions.
14 changes: 14 additions & 0 deletions services/market-data-feeder/src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#![forbid(unsafe_code)]
#![warn(clippy::pedantic)]
#![allow(clippy::missing_errors_doc)]

use chain_ops::run_app;

use market_data_feeder::task::{ApplicationDefinedContext, Id};

run_app!(
task_creation_context: {
ApplicationDefinedContext::new()
},
startup_tasks: [] as [Id; 0],
);
1 change: 1 addition & 0 deletions services/market-data-feeder/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod oracle;
pub mod provider;
pub mod providers;
pub mod task;
Original file line number Diff line number Diff line change
@@ -1,33 +1,26 @@
#![forbid(unsafe_code)]
#![warn(clippy::pedantic)]
#![allow(clippy::missing_errors_doc)]

use std::{collections::BTreeMap, time::Duration};

use anyhow::{Context as _, Result};
use cosmrs::Gas;

use chain_ops::{env::ReadFromVar as _, node, run_app};
use chain_ops::{env::ReadFromVar, node};

mod task;
pub struct ApplicationDefined {
pub(super) dex_node_clients: BTreeMap<String, node::Client>,
pub(super) duration_before_start: Duration,
pub(super) gas_limit: Gas,
pub(super) update_currencies_interval: Duration,
}

run_app!(
task_creation_context: {
Ok(ApplicationDefinedContext {
impl ApplicationDefined {
pub fn new() -> Result<Self> {
Ok(ApplicationDefined {
dex_node_clients: BTreeMap::new(),
duration_before_start: read_duration_before_start()?,
gas_limit: read_gas_limit()?,
update_currencies_interval: read_update_currencies_interval()?,
})
},
startup_tasks: None::<task::Id>.into_iter(),
);

struct ApplicationDefinedContext {
dex_node_clients: BTreeMap<String, node::Client>,
duration_before_start: Duration,
gas_limit: Gas,
update_currencies_interval: Duration,
}
}

fn read_duration_before_start() -> Result<Duration> {
Expand Down
10 changes: 4 additions & 6 deletions services/market-data-feeder/src/task/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@ use chain_ops::{
tx::ExecuteTemplate,
};

use market_data_feeder::{
use crate::{
oracle::Oracle,
providers::{astroport::Astroport, osmosis::Osmosis, Provider},
};

use crate::ApplicationDefinedContext;

use super::{Base, Task};
use super::{context, Base, Task};

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub(crate) struct Id {
pub struct Id {
protocol: Arc<str>,
}

Expand Down Expand Up @@ -80,7 +78,7 @@ impl Id {
impl application_defined::Id for Id {
type ServiceConfiguration = configuration::Service;

type TaskCreationContext = ApplicationDefinedContext;
type TaskCreationContext = context::ApplicationDefined;

type Task = Task;

Expand Down
10 changes: 7 additions & 3 deletions services/market-data-feeder/src/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ use chain_ops::{
tx::ExecuteTemplate,
};

use market_data_feeder::{oracle::Oracle, providers};
use crate::{oracle::Oracle, providers};

pub(crate) use self::id::Id;
use self::provider::Provider;

pub use self::{
context::ApplicationDefined as ApplicationDefinedContext, id::Id,
};

mod context;
mod id;
mod provider;

pub(crate) struct Task {
pub struct Task {
base: Base,
provider: providers::Provider,
}
Expand Down
9 changes: 4 additions & 5 deletions services/market-data-feeder/src/task/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ use chain_ops::{
tx,
};

use market_data_feeder::provider::{
self, Amount, Base, CurrencyPair, Decimal, Quote,
use crate::{
provider::{self, Amount, Base, CurrencyPair, Decimal, Quote},
task,
};

use crate::task;

macro_rules! log {
($macro:ident!($($body:tt)+)) => {
::tracing::$macro!(
Expand Down Expand Up @@ -559,7 +558,7 @@ struct Coin {
fn test_pretty_price_formatting() {
use chain_ops::node;

use market_data_feeder::oracle::Oracle;
use crate::oracle::Oracle;

enum Never {}

Expand Down

0 comments on commit ccafab8

Please sign in to comment.