Skip to content

Commit 2b48692

Browse files
authored
Merge pull request #314 from AdExNetwork/supermarket-changes
Supermarket changes
2 parents 53b1ba9 + 430b768 commit 2b48692

File tree

7 files changed

+133
-25
lines changed

7 files changed

+133
-25
lines changed

Cargo.lock

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

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 <[email protected]>"]
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ hex = "0.3.2"
2727
merkletree = "0.10.0"
2828
tiny-keccak = "1.5"
2929
rust-crypto = "0.2"
30+
url = { version = "2.1", features = ["serde"]}
3031
# Numbers - BigNum, Numbers, Traits and Derives
3132
num-bigint = { version = "0.2", features = ["serde"] }
3233
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/supermarket.rs

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,110 @@ pub enum Finalized {
3939
Exhausted,
4040
Withdraw,
4141
}
42+
pub mod units_for_slot {
43+
pub mod response {
44+
use crate::{targeting::Rule, BigNum, ChannelId, ChannelSpec, SpecValidators, ValidatorId};
45+
use chrono::{
46+
serde::{ts_milliseconds, ts_milliseconds_option},
47+
DateTime, Utc,
48+
};
49+
use serde::{Deserialize, Serialize};
50+
use url::Url;
51+
52+
#[derive(Debug, Serialize, Deserialize)]
53+
#[serde(rename_all = "camelCase")]
54+
pub struct Response {
55+
// TODO: This should be Input, however, we only need the fields and not the Global: Channel, Status & BalancesMap
56+
pub targeting_input_base: (),
57+
pub accepted_referrers: Vec<Url>,
58+
pub fallback_unit: AdUnit,
59+
pub campaigns: Vec<Campaign>,
60+
}
61+
62+
#[derive(Debug, Serialize, Deserialize)]
63+
#[serde(rename_all = "camelCase")]
64+
pub struct UnitsWithPrice {
65+
pub unit: AdUnit,
66+
pub price: BigNum,
67+
}
68+
69+
#[derive(Debug, Serialize, Deserialize)]
70+
#[serde(rename_all = "camelCase")]
71+
pub struct Campaign {
72+
#[serde(flatten)]
73+
pub channel: Channel,
74+
pub targeting_rules: Vec<Rule>,
75+
pub units_with_price: Vec<UnitsWithPrice>,
76+
}
77+
78+
#[derive(Debug, Serialize, Deserialize)]
79+
#[serde(rename_all = "camelCase")]
80+
pub struct Channel {
81+
pub id: ChannelId,
82+
pub creator: ValidatorId,
83+
pub deposit_asset: String,
84+
pub deposit_amount: BigNum,
85+
pub spec: Spec,
86+
}
87+
88+
impl From<crate::Channel> for Channel {
89+
fn from(channel: crate::Channel) -> Self {
90+
Self {
91+
id: channel.id,
92+
creator: channel.creator,
93+
deposit_asset: channel.deposit_asset,
94+
deposit_amount: channel.deposit_amount,
95+
spec: channel.spec.into(),
96+
}
97+
}
98+
}
99+
100+
#[derive(Debug, Serialize, Deserialize)]
101+
#[serde(rename_all = "camelCase")]
102+
pub struct Spec {
103+
#[serde(with = "ts_milliseconds")]
104+
pub withdraw_period_start: DateTime<Utc>,
105+
#[serde(
106+
default,
107+
skip_serializing_if = "Option::is_none",
108+
with = "ts_milliseconds_option"
109+
)]
110+
pub active_from: Option<DateTime<Utc>>,
111+
#[serde(with = "ts_milliseconds")]
112+
pub created: DateTime<Utc>,
113+
pub validators: SpecValidators,
114+
}
115+
116+
impl From<ChannelSpec> for Spec {
117+
fn from(channel_spec: ChannelSpec) -> Self {
118+
Self {
119+
withdraw_period_start: channel_spec.withdraw_period_start,
120+
active_from: channel_spec.active_from,
121+
created: channel_spec.created,
122+
validators: channel_spec.validators,
123+
}
124+
}
125+
}
126+
127+
#[derive(Debug, Serialize, Deserialize, Clone)]
128+
#[serde(rename_all = "camelCase")]
129+
pub struct AdUnit {
130+
/// Same as `ipfs`
131+
pub id: String,
132+
pub media_url: String,
133+
pub media_mime: String,
134+
pub target_url: String,
135+
}
136+
137+
impl From<&crate::AdUnit> for AdUnit {
138+
fn from(ad_unit: &crate::AdUnit) -> Self {
139+
Self {
140+
id: ad_unit.ipfs.clone(),
141+
media_url: ad_unit.media_url.clone(),
142+
media_mime: ad_unit.media_mime.clone(),
143+
target_url: ad_unit.target_url.clone(),
144+
}
145+
}
146+
}
147+
}
148+
}

primitives/src/targeting.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ impl Input {
159159
}
160160
}
161161

162-
fn get_pricing_bounds(channel: &Channel, event_type: &str) -> Pricing {
162+
pub fn get_pricing_bounds(channel: &Channel, event_type: &str) -> Pricing {
163163
channel
164164
.spec
165165
.pricing_bounds

sentry/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ pub struct Application<A: Adapter> {
9999
pub pool: DbPool,
100100
pub config: Config,
101101
pub event_aggregator: EventAggregator,
102-
__secret: (),
103102
}
104103

105104
impl<A: Adapter + 'static> Application<A> {
@@ -117,7 +116,6 @@ impl<A: Adapter + 'static> Application<A> {
117116
redis,
118117
pool,
119118
event_aggregator: Default::default(),
120-
__secret: (),
121119
}
122120
}
123121

0 commit comments

Comments
 (0)