Skip to content

Commit 4614ae7

Browse files
committed
sentry - GET /v5/units-for-slot:
- primitives - sentry - units_for_slot move from supermarket - refactor units-for-slot route - sentry - PlatformApi - refactor and remove old code - primitives - platform - response refactor - sentry - units_for_slot - refactor response
1 parent 76f7a91 commit 4614ae7

File tree

10 files changed

+177
-268
lines changed

10 files changed

+177
-268
lines changed

adview-manager/serve/src/routes.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use std::sync::Arc;
22

33
use adex_primitives::{
4-
sentry::IMPRESSION,
5-
supermarket::units_for_slot,
4+
sentry::{units_for_slot, IMPRESSION},
65
targeting::{input::Global, Input},
76
test_util::{DUMMY_CAMPAIGN, DUMMY_IPFS},
87
ToHex,
@@ -110,9 +109,9 @@ pub async fn get_preview_ad(Extension(state): Extension<Arc<State>>) -> Html<Str
110109

111110
debug!("Mocked response: {demand_resp:?}");
112111

113-
let supermarket_ad_unit = adex_primitives::supermarket::units_for_slot::response::AdUnit {
112+
let supermarket_ad_unit = adex_primitives::sentry::units_for_slot::response::AdUnit {
114113
/// Same as `ipfs`
115-
id: DUMMY_IPFS[1],
114+
ipfs: DUMMY_IPFS[1],
116115
media_url: "ipfs://QmcUVX7fvoLMM93uN2bD3wGTH8MXSxeL8hojYfL2Lhp7mR".to_string(),
117116
media_mime: "image/jpeg".to_string(),
118117
target_url: "https://www.adex.network/?stremio-test-banner-1".to_string(),
@@ -163,9 +162,9 @@ pub async fn get_preview_video(Extension(state): Extension<Arc<State>>) -> Html<
163162
};
164163

165164
// legacy_728x90
166-
let video_ad_unit = adex_primitives::supermarket::units_for_slot::response::AdUnit {
165+
let video_ad_unit = adex_primitives::sentry::units_for_slot::response::AdUnit {
167166
/// Same as `ipfs`
168-
id: "QmShJ6tsJ7LHLiYGX4EAmPyCPWJuCnvm6AKjweQPnw9qfh"
167+
ipfs: "QmShJ6tsJ7LHLiYGX4EAmPyCPWJuCnvm6AKjweQPnw9qfh"
169168
.parse()
170169
.expect("Valid IPFS"),
171170
media_url: "ipfs://Qmevmms1AZgYXS27A9ghSjHn4DSaHMfgYcD2SoGW14RYGy".to_string(),

adview-manager/src/helpers.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ use std::ops::{Add, Mul};
22

33
use adex_primitives::{
44
campaign::Validators,
5-
sentry::{Event, EventType, InsertEventsRequest, CLICK, IMPRESSION},
6-
supermarket::units_for_slot::response::AdUnit,
5+
sentry::{
6+
units_for_slot::response::AdUnit, Event, EventType, InsertEventsRequest, CLICK, IMPRESSION,
7+
},
78
BigNum, CampaignId,
89
};
910
use num_integer::Integer;
@@ -68,7 +69,7 @@ pub(crate) fn is_video(ad_unit: &AdUnit) -> bool {
6869

6970
/// Does not copy the JS impl, instead it generates the BigNum from the IPFS CID bytes
7071
pub(crate) fn randomized_sort_pos(ad_unit: &AdUnit, seed: BigNum) -> BigNum {
71-
let bytes = ad_unit.id.0.to_bytes();
72+
let bytes = ad_unit.ipfs.0.to_bytes();
7273

7374
let unit_id = BigNum::from_bytes_be(&bytes);
7475

@@ -138,13 +139,13 @@ pub fn get_unit_html_with_events(
138139
let event = match event_type {
139140
EventType::Impression => Event::Impression {
140141
publisher: options.publisher_addr,
141-
ad_unit: ad_unit.id,
142+
ad_unit: ad_unit.ipfs,
142143
ad_slot: options.market_slot,
143144
referrer: Some("document.referrer".to_string()),
144145
},
145146
EventType::Click => Event::Click {
146147
publisher: options.publisher_addr,
147-
ad_unit: ad_unit.id,
148+
ad_unit: ad_unit.ipfs,
148149
ad_slot: options.market_slot,
149150
referrer: Some("document.referrer".to_string()),
150151
},
@@ -204,7 +205,7 @@ mod test {
204205

205206
fn get_ad_unit(media_mime: &str) -> AdUnit {
206207
AdUnit {
207-
id: DUMMY_IPFS[0],
208+
ipfs: DUMMY_IPFS[0],
208209
media_url: "".to_string(),
209210
media_mime: media_mime.to_string(),
210211
target_url: "".to_string(),
@@ -237,7 +238,7 @@ mod test {
237238
#[test]
238239
fn test_randomized_position() {
239240
let ad_unit = AdUnit {
240-
id: DUMMY_IPFS[0],
241+
ipfs: DUMMY_IPFS[0],
241242
media_url: "ipfs://QmWWQSuPMS6aXCbZKpEjPHPUZN2NjB3YrhJTHsV4X3vb2t".to_string(),
242243
media_mime: "image/jpeg".to_string(),
243244
target_url: "https://google.com".to_string(),

adview-manager/src/manager.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//! The AdView Manager
22
use adex_primitives::{
3-
sentry::IMPRESSION,
4-
supermarket::units_for_slot,
5-
supermarket::units_for_slot::response::{AdUnit, Campaign},
3+
sentry::{
4+
units_for_slot::response::{AdUnit, Campaign, Response},
5+
IMPRESSION,
6+
},
67
targeting::{self, input},
78
util::ApiUrl,
89
Address, BigNum, CampaignId, ToHex, UnifiedNum, IPFS,
@@ -200,7 +201,7 @@ impl Manager {
200201
.units_with_price
201202
.iter()
202203
.find_map(|u| {
203-
if u.unit.id == sticky_entry.unit_id {
204+
if u.unit.ipfs == sticky_entry.unit_id {
204205
Some(u.unit.clone())
205206
} else {
206207
None
@@ -239,9 +240,7 @@ impl Manager {
239240
}
240241
}
241242

242-
pub async fn get_market_demand_resp(
243-
&self,
244-
) -> Result<units_for_slot::response::Response, Error> {
243+
pub async fn get_market_demand_resp(&self) -> Result<Response, Error> {
245244
let pub_prefix = self.options.publisher_addr.to_hex();
246245

247246
let deposit_asset = self
@@ -320,7 +319,7 @@ impl Manager {
320319
.units_with_price
321320
.iter()
322321
.filter(|unit_with_price| {
323-
unit_input.ad_unit_id = Some(unit_with_price.unit.id);
322+
unit_input.ad_unit_id = Some(unit_with_price.unit.ipfs);
324323

325324
let mut output = targeting::Output {
326325
show: true,
@@ -359,7 +358,7 @@ impl Manager {
359358

360359
let new_entry = HistoryEntry {
361360
time: Utc::now(),
362-
unit_id: unit_with_price.unit.id,
361+
unit_id: unit_with_price.unit.ipfs,
363362
campaign_id: *campaign_id,
364363
slot_id: self.options.market_slot,
365364
};

primitives/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ pub mod merkle_tree;
4444
pub mod platform;
4545
pub mod sentry;
4646
pub mod spender;
47-
pub mod supermarket;
4847
pub mod targeting;
4948
// It's not possible to enable this feature for doctest,
5049
// so we always must pass `--feature=test-util` or `--all-features` when running doctests:

primitives/src/platform.rs

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
1-
pub use ad_unit::{AdUnitResponse, AdUnitsResponse};
1+
use std::collections::HashSet;
22

3-
mod ad_unit {
4-
use crate::AdUnit;
5-
use serde::{Deserialize, Serialize};
3+
use serde::{Deserialize, Serialize};
4+
use url::Url;
65

7-
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
8-
#[serde(rename_all = "camelCase")]
9-
pub struct AdUnitsResponse(pub Vec<AdUnit>);
6+
use crate::{AdSlot, AdUnit};
107

11-
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
12-
#[serde(rename_all = "camelCase")]
13-
pub struct AdUnitResponse {
14-
pub unit: AdUnit,
15-
}
8+
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
9+
pub struct Website {
10+
#[serde(default)]
11+
pub categories: HashSet<String>,
12+
#[serde(default)]
13+
pub accepted_referrers: Vec<Url>,
14+
}
15+
16+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
17+
#[serde(rename_all = "camelCase")]
18+
pub struct AdSlotResponse {
19+
pub slot: AdSlot,
20+
/// The fetched Fallback [`AdUnit`] ( [`AdSlot.fallback_unit`] ) of the [`AdSlot`] if set.
21+
///
22+
/// [`AdSlot.fallback_unit`]: AdSlot::fallback_unit
23+
#[serde(default)]
24+
pub fallback: Option<AdUnit>,
25+
/// The [`AdSlot.website`] information if it's provided and information is available for it.
26+
///
27+
/// [`AdSlot.website`]: AdSlot::website
28+
#[serde(default, flatten)]
29+
pub website: Option<Website>,
1630
}

primitives/src/sentry.rs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,72 @@ pub mod campaign_modify {
11501150
}
11511151
}
11521152

1153+
pub mod units_for_slot {
1154+
use std::collections::HashSet;
1155+
1156+
use serde::{Deserialize, Serialize};
1157+
1158+
use crate::Address;
1159+
1160+
#[derive(Debug, Clone, Serialize, Deserialize)]
1161+
#[serde(rename_all = "camelCase")]
1162+
pub struct Query {
1163+
pub deposit_assets: HashSet<Address>,
1164+
}
1165+
1166+
pub mod response {
1167+
use serde::{Deserialize, Serialize};
1168+
use url::Url;
1169+
1170+
use crate::{targeting::Input, UnifiedNum, IPFS};
1171+
1172+
#[derive(Debug, Serialize, Deserialize, PartialEq)]
1173+
#[serde(rename_all = "camelCase")]
1174+
pub struct Response {
1175+
pub targeting_input_base: Input,
1176+
pub accepted_referrers: Vec<Url>,
1177+
pub fallback_unit: Option<AdUnit>,
1178+
pub campaigns: Vec<Campaign>,
1179+
}
1180+
1181+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
1182+
#[serde(rename_all = "camelCase")]
1183+
pub struct UnitsWithPrice {
1184+
pub unit: AdUnit,
1185+
pub price: UnifiedNum,
1186+
}
1187+
1188+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
1189+
#[serde(rename_all = "camelCase")]
1190+
pub struct Campaign {
1191+
#[serde(flatten)]
1192+
pub campaign: crate::Campaign,
1193+
/// units-for-slot Specific Campaign field
1194+
pub units_with_price: Vec<UnitsWithPrice>,
1195+
}
1196+
1197+
#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
1198+
#[serde(rename_all = "camelCase")]
1199+
pub struct AdUnit {
1200+
pub ipfs: IPFS,
1201+
pub media_url: String,
1202+
pub media_mime: String,
1203+
pub target_url: String,
1204+
}
1205+
1206+
impl From<&crate::AdUnit> for AdUnit {
1207+
fn from(ad_unit: &crate::AdUnit) -> Self {
1208+
Self {
1209+
ipfs: ad_unit.ipfs,
1210+
media_url: ad_unit.media_url.clone(),
1211+
media_mime: ad_unit.media_mime.clone(),
1212+
target_url: ad_unit.target_url.clone(),
1213+
}
1214+
}
1215+
}
1216+
}
1217+
}
1218+
11531219
#[cfg(feature = "postgres")]
11541220
mod postgres {
11551221
use bytes::BytesMut;

primitives/src/supermarket.rs

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)