Skip to content

Commit 71de92d

Browse files
committed
Merge remote-tracking branch 'upstream/dev' into dev
2 parents 9dad371 + 33e0357 commit 71de92d

32 files changed

+1895
-263
lines changed

Cargo.lock

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

adapter/src/dummy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ impl Adapter for DummyAdapter {
103103

104104
match identity {
105105
Some((id, _)) => Ok(Session {
106-
uid: self.session_tokens[id].clone(),
106+
uid: self.session_tokens[id],
107107
era: 0,
108108
}),
109109
None => Err(AdapterError::Authentication(format!(

adview-manager/src/lib.rs

Lines changed: 33 additions & 27 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::{AdUnit, BigNum, ChannelId, 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}\">
@@ -294,8 +296,12 @@ fn get_unit_html(
294296
#[cfg(test)]
295297
mod test {
296298
use super::*;
299+
use adex_primitives::ValidatorId;
300+
use std::convert::TryFrom;
297301

298302
fn get_ad_unit(media_mime: &str) -> AdUnit {
303+
let owner = ValidatorId::try_from("0xce07CbB7e054514D590a0262C93070D838bFBA2e")
304+
.expect("Should be valid ValidatorId string");
299305
AdUnit {
300306
ipfs: "".to_string(),
301307
ad_type: "".to_string(),
@@ -305,7 +311,7 @@ mod test {
305311
targeting: vec![],
306312
min_targeting_score: None,
307313
tags: vec![],
308-
owner: "".to_string(),
314+
owner,
309315
created: Utc::now(),
310316
title: None,
311317
description: None,

docs/config/dev.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ health_threshold_promilles = 950
1313
health_unsignable_promilles = 750
1414
propagation_timeout = 1000
1515

16-
list_timeout = 5000
1716
fetch_timeout = 5000
1817
validator_tick_timeout = 5000
1918

docs/config/prod.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ health_threshold_promilles = 970
1313
health_unsignable_promilles = 770
1414
propagation_timeout = 3000
1515

16-
list_timeout = 10000
1716
fetch_timeout = 10000
1817
validator_tick_timeout = 10000
1918

primitives/src/ad_slot.rs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
use crate::{BigNum, TargetingTag, ValidatorId};
2+
use chrono::serde::{ts_milliseconds, ts_milliseconds_option};
3+
use chrono::{DateTime, Utc};
4+
use serde::{Deserialize, Serialize};
5+
use std::collections::HashMap;
6+
7+
/// See [AdEx Protocol adSlot.md][protocol] & [adex-models AdSlot.js][adex-models] for more details.
8+
/// [protocol]: https://github.com/AdExNetwork/adex-protocol/blob/master/adSlot.md
9+
/// [adex-models]: https://github.com/AdExNetwork/adex-models/blob/master/src/models/AdSlot.js
10+
#[derive(Serialize, Deserialize, Debug, Clone)]
11+
#[serde(rename_all = "camelCase")]
12+
pub struct AdSlot {
13+
/// valid ipfs hash of spec props below
14+
pub ipfs: String,
15+
/// The type of the AdSlot
16+
/// currently, possible values are:
17+
/// > legacy_300x250, legacy_250x250, legacy_240x400, legacy_336x280,
18+
/// > legacy_180x150, legacy_300x100, legacy_720x300, legacy_468x60,
19+
/// > legacy_234x60, legacy_88x31, legacy_120x90, legacy_120x60,
20+
/// > legacy_120x240, legacy_125x125, legacy_728x90, legacy_160x600,
21+
/// > legacy_120x600, legacy_300x600
22+
/// see IAB ad unit guidelines and iab_flex_{adUnitName} (see IAB's new ad portfolio and PDF)
23+
#[serde(rename = "type")]
24+
pub ad_type: String,
25+
/// A URL to the resource (usually PNG)
26+
/// * must use the ipfs:// protocol, to guarantee data immutability
27+
pub media_url: String,
28+
/// MIME type of the media.
29+
// Possible values at the moment are:
30+
/// * image/jpeg
31+
/// * image/png
32+
pub media_mime: String,
33+
/// Advertised URL
34+
pub target_url: String,
35+
/// Array of TargetingTag
36+
#[serde(default)]
37+
pub targeting: Vec<TargetingTag>,
38+
// HashMap<DepositAsset, BigNum> for the minimum payment accepted per impression
39+
#[serde(default)]
40+
pub min_per_impression: Option<HashMap<String, BigNum>>,
41+
/// Array of TargetingTag
42+
/// meant for discovery between publishers/advertisers
43+
#[serde(default)]
44+
pub tags: Vec<TargetingTag>,
45+
#[serde(default)]
46+
pub auto_tags: Vec<TargetingTag>,
47+
/// Valid ipfs hash for Ad Unit object. It will be used as fallback data (optional)
48+
#[serde(default)]
49+
pub fallback_unit: Option<String>,
50+
/// User address from the session
51+
pub owner: ValidatorId,
52+
/// UTC timestamp in milliseconds, used as nonce for escaping duplicated spec ipfs hashes
53+
#[serde(with = "ts_milliseconds")]
54+
pub created: DateTime<Utc>,
55+
/// the name of the unit used in platform UI
56+
#[serde(default)]
57+
pub title: Option<String>,
58+
/// arbitrary text used in platform UI
59+
#[serde(default)]
60+
pub description: Option<String>,
61+
#[serde(default)]
62+
pub website: Option<String>,
63+
/// user can change it - used for filtering in platform UI
64+
#[serde(default)]
65+
pub archived: bool,
66+
/// UTC timestamp in milliseconds, changed every time modifiable property is changed
67+
#[serde(default, with = "ts_milliseconds_option")]
68+
pub modified: Option<DateTime<Utc>>,
69+
}

primitives/src/ad_unit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use chrono::serde::{ts_milliseconds, ts_milliseconds_option};
22
use chrono::{DateTime, Utc};
33
use serde::{Deserialize, Serialize};
44

5-
use crate::TargetingTag;
5+
use crate::{TargetingTag, ValidatorId};
66

77
#[derive(Serialize, Deserialize, Debug, Clone)]
88
#[serde(rename_all = "camelCase")]
@@ -34,7 +34,7 @@ pub struct AdUnit {
3434
#[serde(default)]
3535
pub tags: Vec<TargetingTag>,
3636
/// user address from the session
37-
pub owner: String,
37+
pub owner: ValidatorId,
3838
/// number, UTC timestamp in milliseconds, used as nonce for escaping duplicated spec ipfs hashes
3939
#[serde(with = "ts_milliseconds")]
4040
pub created: DateTime<Utc>,

0 commit comments

Comments
 (0)