Skip to content

Commit ea5f087

Browse files
committed
primitives - supermarket - /units-for-slot response
1 parent d0f70fc commit ea5f087

File tree

3 files changed

+115
-8
lines changed

3 files changed

+115
-8
lines changed

Cargo.lock

Lines changed: 13 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 <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/src/supermarket.rs

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

0 commit comments

Comments
 (0)