Skip to content

Commit e566cb8

Browse files
authored
Merge pull request #295 from AdExNetwork/clean-up-marketing-campaign
Clean up for Supermarket
2 parents 74618d4 + b69aad9 commit e566cb8

File tree

8 files changed

+94
-18
lines changed

8 files changed

+94
-18
lines changed

adview-manager/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,12 @@ fn get_unit_html(
296296
#[cfg(test)]
297297
mod test {
298298
use super::*;
299+
use adex_primitives::ValidatorId;
300+
use std::convert::TryFrom;
299301

300302
fn get_ad_unit(media_mime: &str) -> AdUnit {
303+
let owner = ValidatorId::try_from("0xce07CbB7e054514D590a0262C93070D838bFBA2e")
304+
.expect("Should be valid ValidatorId string");
301305
AdUnit {
302306
ipfs: "".to_string(),
303307
ad_type: "".to_string(),
@@ -307,7 +311,7 @@ mod test {
307311
targeting: vec![],
308312
min_targeting_score: None,
309313
tags: vec![],
310-
owner: "".to_string(),
314+
owner,
311315
created: Utc::now(),
312316
title: None,
313317
description: None,

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 webiste: 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>,

primitives/src/balances_map.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ impl BalancesMap {
3939
pub fn insert(&mut self, key: ValidatorId, value: BigNum) -> Option<BigNum> {
4040
self.0.insert(key, value)
4141
}
42+
43+
pub fn is_empty(&self) -> bool {
44+
self.0.is_empty()
45+
}
4246
}
4347

4448
impl FromIterator<(ValidatorId, BigNum)> for BalancesMap {

primitives/src/big_num.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::convert::TryFrom;
2+
use std::fmt;
23
use std::iter::Sum;
34
use std::ops::{Add, AddAssign, Div, Mul, Sub};
45
use std::str::FromStr;
@@ -9,19 +10,7 @@ use num_derive::{Num, NumOps, One, Zero};
910
use serde::{Deserialize, Deserializer, Serialize, Serializer};
1011

1112
#[derive(
12-
Serialize,
13-
Deserialize,
14-
Debug,
15-
Clone,
16-
PartialEq,
17-
Eq,
18-
PartialOrd,
19-
Ord,
20-
NumOps,
21-
One,
22-
Zero,
23-
Num,
24-
Default,
13+
Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, NumOps, One, Zero, Num, Default,
2514
)]
2615
pub struct BigNum(
2716
#[serde(
@@ -57,6 +46,14 @@ impl BigNum {
5746
}
5847
}
5948

49+
impl fmt::Debug for BigNum {
50+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
51+
let radix = 10;
52+
let value = self.to_str_radix(radix);
53+
write!(f, "BigNum(radix: {}; {})", radix, value)
54+
}
55+
}
56+
6057
impl Integer for BigNum {
6158
fn div_floor(&self, other: &Self) -> Self {
6259
self.0.div_floor(&other.0).into()

primitives/src/channel.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ pub struct ChannelSpec {
153153
pub ad_units: Vec<AdUnit>,
154154
#[serde(default, skip_serializing_if = "Vec::is_empty")]
155155
pub price_multiplication_rules: Vec<PriceMultiplicationRules>,
156+
#[serde(default)]
156157
pub price_dynamic_adjustment: bool,
157158
}
158159

primitives/src/config.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use lazy_static::lazy_static;
44
use serde::{Deserialize, Serialize};
55
use serde_hex::{SerHex, StrictPfx};
66
use std::fs;
7-
use toml;
87

98
lazy_static! {
109
static ref DEVELOPMENT_CONFIG: Config =

primitives/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
use std::error;
44
use std::fmt;
55

6-
pub mod ad_unit;
6+
mod ad_slot;
7+
mod ad_unit;
78
pub mod adapter;
89
pub mod balances_map;
910
pub mod big_num;
@@ -27,6 +28,7 @@ pub mod analytics;
2728
mod eth_checksum;
2829
pub mod validator;
2930

31+
pub use self::ad_slot::AdSlot;
3032
pub use self::ad_unit::AdUnit;
3133
pub use self::balances_map::BalancesMap;
3234
pub use self::big_num::BigNum;

0 commit comments

Comments
 (0)