Skip to content

Commit 1d2ce75

Browse files
committed
2 parents 71de92d + 19c9706 commit 1d2ce75

File tree

34 files changed

+2478
-384
lines changed

34 files changed

+2478
-384
lines changed

Cargo.lock

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

adapter/src/ethereum.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,15 +669,17 @@ mod test {
669669
deposit_asset: eth_checksum::checksum(&format!("{:?}", token_contract.address())),
670670
deposit_amount: 2_000.into(),
671671
valid_until: Utc::now() + Duration::days(2),
672+
targeting_rules: vec![],
672673
spec: ChannelSpec {
673674
title: None,
674675
validators: SpecValidators::new(leader_validator_desc, follower_validator_desc),
675676
max_per_impression: 10.into(),
676677
min_per_impression: 10.into(),
677678
targeting: vec![],
679+
targeting_rules: vec![],
678680
min_targeting_score: None,
679681
event_submission: Some(EventSubmission { allow: vec![] }),
680-
created: Some(Utc::now()),
682+
created: Utc::now(),
681683
active_from: None,
682684
nonce: None,
683685
withdraw_period_start: Utc::now() + Duration::days(1),

adapter/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,12 @@ mod test {
225225
.expect("The timestamp should be able to be converted to u64");
226226
BigEndian::write_uint(&mut timestamp_buf[26..], n, 6);
227227

228-
let merkle_tree = MerkleTree::new(&[timestamp_buf]);
228+
let merkle_tree = MerkleTree::new(&[timestamp_buf]).expect("Should instantiate");
229229

230230
let channel_id = "061d5e2a67d0a9a10f1c732bca12a676d83f79663a396f7d87b3e30b9b411088";
231231

232232
let state_root = get_signable_state_root(
233-
&hex::decode(&channel_id).expect("fialed"),
233+
&hex::decode(&channel_id).expect("failed"),
234234
&merkle_tree.root(),
235235
)
236236
.expect("Should get state_root");

adview-manager/Cargo.toml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
[package]
2-
name = "adview-manager"
3-
version = "0.1.0"
42
authors = ["Lachezar Lechev <lachezar@adex.network>"]
53
edition = "2018"
6-
7-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
4+
name = "adview-manager"
5+
version = "0.1.0"
86

97
[dependencies]
108
adex_primitives = {path = "../primitives", package = "primitives"}
11-
num-bigint = { version = "0.2", features = ["serde"] }
12-
serde = {version = "^1.0", features = ['derive']}
9+
chrono = "0.4"
10+
num-bigint = {version = "0.3", features = ["serde"]}
11+
serde = {version = "^1.0", features = ['derive']}
1312
serde_json = "^1.0"
14-
chrono = "0.4"

primitives/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ slog = { version = "^2.5.2" , features = ["max_level_trace"] }
2020
slog-term = "^2.4.2"
2121
slog-async = "^2.3.0"
2222
# Domain
23+
thiserror = "^1.0"
2324
chrono = { version = "0.4", features = ["serde"] }
2425
time = "0.1.42"
2526
hex = "0.3.2"
2627
merkletree = "0.10.0"
2728
tiny-keccak = "1.5"
2829
rust-crypto = "0.2"
30+
url = { version = "2.1", features = ["serde"]}
2931
# Numbers - BigNum, Numbers, Traits and Derives
3032
num-bigint = { version = "0.2", features = ["serde"] }
3133
num = "0.2.0"

primitives/src/ad_slot.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use crate::{BigNum, TargetingTag, ValidatorId};
2-
use chrono::serde::{ts_milliseconds, ts_milliseconds_option};
1+
use crate::{targeting::Rule, BigNum, TargetingTag, ValidatorId};
32
use chrono::{DateTime, Utc};
43
use serde::{Deserialize, Serialize};
54
use std::collections::HashMap;
@@ -22,16 +21,6 @@ pub struct AdSlot {
2221
/// see IAB ad unit guidelines and iab_flex_{adUnitName} (see IAB's new ad portfolio and PDF)
2322
#[serde(rename = "type")]
2423
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,
3524
/// Array of TargetingTag
3625
#[serde(default)]
3726
pub targeting: Vec<TargetingTag>,
@@ -44,13 +33,15 @@ pub struct AdSlot {
4433
pub tags: Vec<TargetingTag>,
4534
#[serde(default)]
4635
pub auto_tags: Vec<TargetingTag>,
36+
/// Targeting rules
37+
#[serde(default)]
38+
pub rules: Vec<Rule>,
4739
/// Valid ipfs hash for Ad Unit object. It will be used as fallback data (optional)
4840
#[serde(default)]
4941
pub fallback_unit: Option<String>,
5042
/// User address from the session
5143
pub owner: ValidatorId,
5244
/// UTC timestamp in milliseconds, used as nonce for escaping duplicated spec ipfs hashes
53-
#[serde(with = "ts_milliseconds")]
5445
pub created: DateTime<Utc>,
5546
/// the name of the unit used in platform UI
5647
#[serde(default)]
@@ -64,6 +55,5 @@ pub struct AdSlot {
6455
#[serde(default)]
6556
pub archived: bool,
6657
/// UTC timestamp in milliseconds, changed every time modifiable property is changed
67-
#[serde(default, with = "ts_milliseconds_option")]
6858
pub modified: Option<DateTime<Utc>>,
6959
}

primitives/src/ad_unit.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use chrono::serde::{ts_milliseconds, ts_milliseconds_option};
21
use chrono::{DateTime, Utc};
32
use serde::{Deserialize, Serialize};
43

@@ -36,7 +35,6 @@ pub struct AdUnit {
3635
/// user address from the session
3736
pub owner: ValidatorId,
3837
/// number, UTC timestamp in milliseconds, used as nonce for escaping duplicated spec ipfs hashes
39-
#[serde(with = "ts_milliseconds")]
4038
pub created: DateTime<Utc>,
4139
/// the name of the unit used in platform UI
4240
pub title: Option<String>,
@@ -46,6 +44,5 @@ pub struct AdUnit {
4644
#[serde(default)]
4745
pub archived: bool,
4846
/// UTC timestamp in milliseconds, changed every time modifiable property is changed
49-
#[serde(default, with = "ts_milliseconds_option")]
5047
pub modified: Option<DateTime<Utc>>,
5148
}

primitives/src/balances_map.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ impl BalancesMap {
3232
self.0.get(key)
3333
}
3434

35+
pub fn contains_key(&self, key: &ValidatorId) -> bool {
36+
self.0.contains_key(key)
37+
}
38+
3539
pub fn entry(&mut self, key: ValidatorId) -> Entry<'_, ValidatorId, BigNum> {
3640
self.0.entry(key)
3741
}
@@ -40,6 +44,10 @@ impl BalancesMap {
4044
self.0.insert(key, value)
4145
}
4246

47+
pub fn len(&self) -> usize {
48+
self.0.len()
49+
}
50+
4351
pub fn is_empty(&self) -> bool {
4452
self.0.is_empty()
4553
}

primitives/src/channel.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
use std::error::Error;
22
use std::fmt;
3+
use std::ops::Deref;
34

45
use chrono::serde::{ts_milliseconds, ts_milliseconds_option, ts_seconds};
56
use chrono::{DateTime, Utc};
67
use serde::{Deserialize, Deserializer, Serialize};
78
use serde_hex::{SerHex, StrictPfx};
89

9-
use crate::big_num::BigNum;
10-
use crate::{AdUnit, EventSubmission, TargetingTag, ValidatorDesc, ValidatorId};
10+
use crate::{
11+
targeting::Rule, AdUnit, BigNum, EventSubmission, TargetingTag, ValidatorDesc, ValidatorId,
12+
};
1113
use hex::{FromHex, FromHexError};
12-
use std::ops::Deref;
1314

1415
#[derive(Serialize, Deserialize, PartialEq, Eq, Copy, Clone, Hash)]
1516
#[serde(transparent)]
@@ -84,6 +85,8 @@ pub struct Channel {
8485
pub deposit_amount: BigNum,
8586
#[serde(with = "ts_seconds")]
8687
pub valid_until: DateTime<Utc>,
88+
#[serde(default)]
89+
pub targeting_rules: Vec<Rule>,
8790
pub spec: ChannelSpec,
8891
}
8992

@@ -116,6 +119,14 @@ impl PricingBounds {
116119

117120
vec
118121
}
122+
123+
pub fn get(&self, event_type: &str) -> Option<&Pricing> {
124+
match event_type {
125+
"IMPRESSION" => self.impression.as_ref(),
126+
"CLICK" => self.click.as_ref(),
127+
_ => None,
128+
}
129+
}
119130
}
120131

121132
#[derive(Serialize, Deserialize, Debug, Clone)]
@@ -141,14 +152,10 @@ pub struct ChannelSpec {
141152
#[serde(default, skip_serializing_if = "Option::is_none")]
142153
pub event_submission: Option<EventSubmission>,
143154
/// A millisecond timestamp of when the campaign was created
144-
#[serde(
145-
default,
146-
skip_serializing_if = "Option::is_none",
147-
with = "ts_milliseconds_option"
148-
)]
149-
pub created: Option<DateTime<Utc>>,
155+
#[serde(with = "ts_milliseconds")]
156+
pub created: DateTime<Utc>,
150157
/// A millisecond timestamp representing the time you want this campaign to become active (optional)
151-
/// Used by the AdViewManager
158+
/// Used by the AdViewManager & Targeting AIP#31
152159
#[serde(
153160
default,
154161
skip_serializing_if = "Option::is_none",
@@ -167,6 +174,8 @@ pub struct ChannelSpec {
167174
/// An array of AdUnit (optional)
168175
#[serde(default, skip_serializing_if = "Vec::is_empty")]
169176
pub ad_units: Vec<AdUnit>,
177+
#[serde(default)]
178+
pub targeting_rules: Vec<Rule>,
170179
#[serde(default, skip_serializing_if = "Vec::is_empty")]
171180
pub price_multiplication_rules: Vec<PriceMultiplicationRules>,
172181
#[serde(default)]
@@ -335,6 +344,7 @@ impl Error for ChannelError {
335344
pub mod postgres {
336345
use super::ChannelId;
337346
use super::{Channel, ChannelSpec};
347+
use crate::targeting::Rule;
338348
use bytes::BytesMut;
339349
use hex::FromHex;
340350
use postgres_types::{accepts, to_sql_checked, FromSql, IsNull, Json, ToSql, Type};
@@ -349,6 +359,7 @@ pub mod postgres {
349359
deposit_asset: row.get("deposit_asset"),
350360
deposit_amount: row.get("deposit_amount"),
351361
valid_until: row.get("valid_until"),
362+
targeting_rules: row.get::<_, Json<Vec<Rule>>>("targeting_rules").0,
352363
spec: row.get::<_, Json<ChannelSpec>>("spec").0,
353364
}
354365
}

primitives/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ pub mod event_submission;
1515
pub mod market;
1616
pub mod merkle_tree;
1717
pub mod sentry;
18+
pub mod supermarket;
1819
pub mod targeting;
1920
pub mod targeting_tag;
21+
2022
pub mod util {
2123
pub mod tests {
2224
pub mod prep_db;

0 commit comments

Comments
 (0)