Skip to content

Commit a8d0421

Browse files
committed
rename module to market & clean up Marketing Channel
1 parent 557f065 commit a8d0421

File tree

5 files changed

+40
-44
lines changed

5 files changed

+40
-44
lines changed

adview-manager/src/lib.rs

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#![deny(rust_2018_idioms)]
22
#![deny(clippy::all)]
33

4-
use adex_primitives::market_channel::{MarketChannel, MarketStatusType};
5-
use adex_primitives::{AdUnit, BigNum, SpecValidators, TargetingTag};
4+
use adex_primitives::market::{Campaign, StatusType};
5+
use adex_primitives::{ChannelId, AdUnit, BigNum, SpecValidators, TargetingTag};
66
use chrono::Utc;
77
use serde::{Deserialize, Serialize};
88

@@ -18,7 +18,7 @@ pub struct AdViewManagerOptions {
1818
#[serde(rename = "marketURL")]
1919
pub market_url: String,
2020
/// Defaulted
21-
pub accepted_states: Vec<MarketStatusType>,
21+
pub accepted_states: Vec<StatusType>,
2222
/// Defaulted
2323
pub min_per_impression: BigNum,
2424
/// Defaulted
@@ -51,7 +51,7 @@ impl AdViewManagerOptions {
5151
#[derive(Debug)]
5252
pub struct UnitByPrice {
5353
pub unit: AdUnit,
54-
pub channel_id: String,
54+
pub channel_id: ChannelId,
5555
pub validators: SpecValidators,
5656
pub min_targeting_score: MinTargetingScore,
5757
pub min_per_impression: BigNum,
@@ -60,7 +60,7 @@ pub struct UnitByPrice {
6060
#[derive(Debug)]
6161
pub struct Unit {
6262
pub unit: AdUnit,
63-
pub channel_id: String,
63+
pub channel_id: ChannelId,
6464
pub validators: SpecValidators,
6565
pub min_targeting_score: MinTargetingScore,
6666
pub min_per_impression: BigNum,
@@ -80,24 +80,26 @@ impl Unit {
8080
}
8181
}
8282

83-
pub fn apply_selection(campaigns: &[MarketChannel], options: &AdViewManagerOptions) -> Vec<Unit> {
83+
pub fn apply_selection(campaigns: &[Campaign], options: &AdViewManagerOptions) -> Vec<Unit> {
8484
let eligible = campaigns.iter().filter(|campaign| {
8585
options
8686
.accepted_states
8787
.contains(&campaign.status.status_type)
8888
&& campaign
89+
.channel
8990
.spec
9091
.active_from
9192
.map(|datetime| datetime < Utc::now())
9293
.unwrap_or(true)
93-
&& campaign.deposit_asset == options.whitelisted_token
94-
&& campaign.spec.min_per_impression >= options.min_per_impression
94+
&& campaign.channel.deposit_asset == options.whitelisted_token
95+
&& campaign.channel.spec.min_per_impression >= options.min_per_impression
9596
});
9697

9798
let mut units: Vec<UnitByPrice> = eligible
9899
// filter ad_units by whitelisted type, map then to UnitByPrice and flat_map them for each campaing
99100
.flat_map(|campaign| {
100101
campaign
102+
.channel
101103
.spec
102104
.ad_units
103105
.iter()
@@ -113,13 +115,13 @@ pub fn apply_selection(campaigns: &[MarketChannel], options: &AdViewManagerOptio
113115
})
114116
.map(move |ad_unit| UnitByPrice {
115117
unit: ad_unit.clone(),
116-
channel_id: campaign.id.clone(),
117-
validators: campaign.spec.validators.clone(),
118+
channel_id: campaign.channel.id,
119+
validators: campaign.channel.spec.validators.clone(),
118120
min_targeting_score: ad_unit
119121
.min_targeting_score
120-
.or(campaign.spec.min_targeting_score)
122+
.or(campaign.channel.spec.min_targeting_score)
121123
.unwrap_or_else(|| 0.into()),
122-
min_per_impression: campaign.spec.min_per_impression.clone(),
124+
min_per_impression: campaign.channel.spec.min_per_impression.clone(),
123125
})
124126
})
125127
.collect();
@@ -223,7 +225,7 @@ fn video_html(
223225
pub fn get_html(
224226
options: &AdViewManagerOptions,
225227
ad_unit: AdUnit,
226-
channel_id: &str,
228+
channel_id: ChannelId,
227229
validators: &SpecValidators,
228230
) -> String {
229231
let ev_body = EventBody {
@@ -267,19 +269,19 @@ fn get_unit_html(
267269
let adex_icon = "<a href=\"https://www.adex.network\" target=\"_blank\" rel=\"noopener noreferrer\"
268270
style=\"position: absolute; top: 0; right: 0;\"
269271
>
270-
<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" x=\"0px\" y=\"0px\" width=\"18px\"
271-
height=\"18px\" viewBox=\"0 0 18 18\" style=\"enable-background:new 0 0 18 18;\" xml:space=\"preserve\">
272-
<style type=\"text/css\">
273-
.st0{fill:#FFFFFF;}
274-
.st1{fill:#1B75BC;}
275-
</style>
276-
<defs>
277-
</defs>
278-
<rect class=\"st0\" width=\"18\" height=\"18\"/>
279-
<path class=\"st1\" d=\"M14,12.1L10.9,9L14,5.9L12.1,4L9,7.1L5.9,4L4,5.9L7.1,9L4,12.1L5.9,14L9,10.9l3.1,3.1L14,12.1z M7.9,2L6.4,3.5
280-
L7.9,5L9,3.9L10.1,5l1.5-1.5L10,1.9l-1-1L7.9,2 M7.9,16l-1.5-1.5L7.9,13L9,14.1l1.1-1.1l1.5,1.5L10,16.1l-1,1L7.9,16\"/>
281-
</svg>
282-
</a>";
272+
<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" x=\"0px\" y=\"0px\" width=\"18px\"
273+
height=\"18px\" viewBox=\"0 0 18 18\" style=\"enable-background:new 0 0 18 18;\" xml:space=\"preserve\">
274+
<style type=\"text/css\">
275+
.st0{fill:#FFFFFF;}
276+
.st1{fill:#1B75BC;}
277+
</style>
278+
<defs>
279+
</defs>
280+
<rect class=\"st0\" width=\"18\" height=\"18\"/>
281+
<path class=\"st1\" d=\"M14,12.1L10.9,9L14,5.9L12.1,4L9,7.1L5.9,4L4,5.9L7.1,9L4,12.1L5.9,14L9,10.9l3.1,3.1L14,12.1z M7.9,2L6.4,3.5
282+
L7.9,5L9,3.9L10.1,5l1.5-1.5L10,1.9l-1-1L7.9,2 M7.9,16l-1.5-1.5L7.9,13L9,14.1l1.1-1.1l1.5,1.5L10,16.1l-1,1L7.9,16\"/>
283+
</svg>
284+
</a>";
283285

284286
let result = format!("
285287
<div style=\"position: relative; overflow: hidden; {size}\">

primitives/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub mod channel;
1111
pub mod channel_validator;
1212
pub mod config;
1313
pub mod event_submission;
14-
pub mod market_channel;
14+
pub mod market;
1515
pub mod merkle_tree;
1616
pub mod sentry;
1717
pub mod targeting_tag;
Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
use chrono::serde::ts_milliseconds;
22
use serde::{Deserialize, Serialize};
3-
use std::collections::HashMap;
43

54
use chrono::{DateTime, Utc};
65

7-
use crate::{BigNum, ChannelSpec};
6+
use crate::{BigNum, Channel, BalancesMap};
87

98
// Data structs specific to the market
109
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
11-
pub enum MarketStatusType {
10+
pub enum StatusType {
1211
Initializing,
1312
Ready,
1413
Active,
@@ -22,29 +21,25 @@ pub enum MarketStatusType {
2221

2322
#[derive(Deserialize, Clone, Debug)]
2423
#[serde(rename_all = "camelCase")]
25-
pub struct MarketStatus {
24+
pub struct Status {
2625
#[serde(rename = "name")]
27-
pub status_type: MarketStatusType,
26+
pub status_type: StatusType,
2827
pub usd_estimate: f32,
2928
#[serde(rename = "lastApprovedBalances")]
30-
pub balances: HashMap<String, BigNum>,
29+
pub balances: BalancesMap,
3130
#[serde(with = "ts_milliseconds")]
3231
pub last_checked: DateTime<Utc>,
3332
}
3433

35-
impl MarketStatus {
34+
impl Status {
3635
pub fn balances_sum(&self) -> BigNum {
3736
self.balances.values().sum()
3837
}
3938
}
4039

4140
#[derive(Deserialize, Clone, Debug)]
4241
#[serde(rename_all = "camelCase")]
43-
pub struct MarketChannel {
44-
pub id: String,
45-
pub creator: String,
46-
pub deposit_asset: String,
47-
pub deposit_amount: BigNum,
48-
pub status: MarketStatus,
49-
pub spec: ChannelSpec,
42+
pub struct Campaign {
43+
pub channel: Channel,
44+
pub status: Status,
5045
}

sentry/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ impl<A: Adapter + 'static> Application<A> {
136136
}
137137
};
138138

139-
let path = req.uri().path().to_string();
140-
let mut response = match (path.as_ref(), req.method()) {
139+
let mut response = match (req.uri().path(), req.method()) {
141140
("/cfg", &Method::GET) => config(req, &self).await,
142141
("/channel", &Method::POST) => create_channel(req, &self).await,
143142
("/channel/list", &Method::GET) => channel_list(req, &self).await,

sentry/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ async fn run<A: Adapter + 'static>(app: Application<A>, port: u16) {
127127
let logger = app.logger.clone();
128128
info!(&logger, "Listening on port {}!", port);
129129

130-
let make_service = make_service_fn(move |_| {
130+
let make_service = make_service_fn(|_| {
131131
let server = app.clone();
132132
async move {
133133
Ok::<_, Error>(service_fn(move |req| {

0 commit comments

Comments
 (0)