Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions adview-manager/serve/src/routes.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::sync::Arc;

use adex_primitives::{
sentry::IMPRESSION,
supermarket::units_for_slot,
sentry::{units_for_slot, IMPRESSION},
targeting::{input::Global, Input},
test_util::{DUMMY_CAMPAIGN, DUMMY_IPFS},
ToHex,
Expand Down Expand Up @@ -110,9 +109,9 @@ pub async fn get_preview_ad(Extension(state): Extension<Arc<State>>) -> Html<Str

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

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

// legacy_728x90
let video_ad_unit = adex_primitives::supermarket::units_for_slot::response::AdUnit {
let video_ad_unit = adex_primitives::sentry::units_for_slot::response::AdUnit {
/// Same as `ipfs`
id: "QmShJ6tsJ7LHLiYGX4EAmPyCPWJuCnvm6AKjweQPnw9qfh"
ipfs: "QmShJ6tsJ7LHLiYGX4EAmPyCPWJuCnvm6AKjweQPnw9qfh"
.parse()
.expect("Valid IPFS"),
media_url: "ipfs://Qmevmms1AZgYXS27A9ghSjHn4DSaHMfgYcD2SoGW14RYGy".to_string(),
Expand Down
15 changes: 8 additions & 7 deletions adview-manager/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use std::ops::{Add, Mul};

use adex_primitives::{
campaign::Validators,
sentry::{Event, EventType, InsertEventsRequest, CLICK, IMPRESSION},
supermarket::units_for_slot::response::AdUnit,
sentry::{
units_for_slot::response::AdUnit, Event, EventType, InsertEventsRequest, CLICK, IMPRESSION,
},
BigNum, CampaignId,
};
use num_integer::Integer;
Expand Down Expand Up @@ -68,7 +69,7 @@ pub(crate) fn is_video(ad_unit: &AdUnit) -> bool {

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

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

Expand Down Expand Up @@ -138,13 +139,13 @@ pub fn get_unit_html_with_events(
let event = match event_type {
EventType::Impression => Event::Impression {
publisher: options.publisher_addr,
ad_unit: ad_unit.id,
ad_unit: ad_unit.ipfs,
ad_slot: options.market_slot,
referrer: Some("document.referrer".to_string()),
},
EventType::Click => Event::Click {
publisher: options.publisher_addr,
ad_unit: ad_unit.id,
ad_unit: ad_unit.ipfs,
ad_slot: options.market_slot,
referrer: Some("document.referrer".to_string()),
},
Expand Down Expand Up @@ -204,7 +205,7 @@ mod test {

fn get_ad_unit(media_mime: &str) -> AdUnit {
AdUnit {
id: DUMMY_IPFS[0],
ipfs: DUMMY_IPFS[0],
media_url: "".to_string(),
media_mime: media_mime.to_string(),
target_url: "".to_string(),
Expand Down Expand Up @@ -237,7 +238,7 @@ mod test {
#[test]
fn test_randomized_position() {
let ad_unit = AdUnit {
id: DUMMY_IPFS[0],
ipfs: DUMMY_IPFS[0],
media_url: "ipfs://QmWWQSuPMS6aXCbZKpEjPHPUZN2NjB3YrhJTHsV4X3vb2t".to_string(),
media_mime: "image/jpeg".to_string(),
target_url: "https://google.com".to_string(),
Expand Down
17 changes: 8 additions & 9 deletions adview-manager/src/manager.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! The AdView Manager
use adex_primitives::{
sentry::IMPRESSION,
supermarket::units_for_slot,
supermarket::units_for_slot::response::{AdUnit, Campaign},
sentry::{
units_for_slot::response::{AdUnit, Campaign, Response},
IMPRESSION,
},
targeting::{self, input},
util::ApiUrl,
Address, BigNum, CampaignId, ToHex, UnifiedNum, IPFS,
Expand Down Expand Up @@ -200,7 +201,7 @@ impl Manager {
.units_with_price
.iter()
.find_map(|u| {
if u.unit.id == sticky_entry.unit_id {
if u.unit.ipfs == sticky_entry.unit_id {
Some(u.unit.clone())
} else {
None
Expand Down Expand Up @@ -239,9 +240,7 @@ impl Manager {
}
}

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

let deposit_asset = self
Expand Down Expand Up @@ -320,7 +319,7 @@ impl Manager {
.units_with_price
.iter()
.filter(|unit_with_price| {
unit_input.ad_unit_id = Some(unit_with_price.unit.id);
unit_input.ad_unit_id = Some(unit_with_price.unit.ipfs);

let mut output = targeting::Output {
show: true,
Expand Down Expand Up @@ -359,7 +358,7 @@ impl Manager {

let new_entry = HistoryEntry {
time: Utc::now(),
unit_id: unit_with_price.unit.id,
unit_id: unit_with_price.unit.ipfs,
campaign_id: *campaign_id,
slot_id: self.options.market_slot,
};
Expand Down
9 changes: 6 additions & 3 deletions docs/config/ganache.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ creators_whitelist = [
'0xaCBaDA2d5830d1875ae3D2de207A1363B316Df2F',
# ADVERTISER
'0xDd589B43793934EF6Ad266067A0d1D4896b0dff0',
# PUBLISHER
'0xE882ebF439207a70dDcCb39E13CA8506c9F45fD9',
# ADVERTISER_2
'0x541b401362Ea1D489D322579552B099e801F3632',
]
Expand Down Expand Up @@ -58,9 +60,10 @@ keep_alive_interval = 1200000
# This will limit the returned Campaigns to the set number
max_campaigns_earning_from = 25

# 0.01 (UnifiedNum) per 1000 impressions
# 1_000 * (per) 1_000 / 10^8 = 0.01
global_min_impression_price = '1000000'
# 0.0001 (UnifiedNum) per 1000 impressions
# 10 * (per) 1_000 / 10^8 = 0.0001
# 0.00010000
global_min_impression_price = '10000'

[chain."Ganache #1"]
chain_id = 1
Expand Down
3 changes: 2 additions & 1 deletion primitives/examples/get_cfg_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ fn main() {
"creators_whitelist": [
"0xaCBaDA2d5830d1875ae3D2de207A1363B316Df2F",
"0xDd589B43793934EF6Ad266067A0d1D4896b0dff0",
"0xE882ebF439207a70dDcCb39E13CA8506c9F45fD9",
"0x541b401362Ea1D489D322579552B099e801F3632"
],
"validators_whitelist": [
Expand Down Expand Up @@ -70,7 +71,7 @@ fn main() {
"limits": {
"units_for_slot": {
"max_campaigns_earning_from": 25,
"global_min_impression_price": "1000000"
"global_min_impression_price": "10000"
}
}
});
Expand Down
14 changes: 9 additions & 5 deletions primitives/src/ad_slot.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{targeting::Rule, Address, UnifiedNum, ValidatorId, IPFS};
use crate::{targeting::Rules, Address, UnifiedNum, ValidatorId, IPFS};
use chrono::{
serde::{ts_milliseconds, ts_milliseconds_option},
DateTime, Utc,
Expand All @@ -25,20 +25,24 @@ pub struct AdSlot {
/// see IAB ad unit guidelines and iab_flex_{adUnitName} (see IAB's new ad portfolio and PDF)
#[serde(rename = "type")]
pub ad_type: String,
/// HashMap<DepositAsset, UnifiedNum> for the minimum payment accepted per impression
/// The minimum [`IMPRESSION`] payment accepted for the slot per deposit asset (token address).
///
/// `HashMap<DepositAsset, UnifiedNum>`
///
/// [`IMPRESSION`]: crate::sentry::IMPRESSION
#[serde(default)]
pub min_per_impression: Option<HashMap<Address, UnifiedNum>>,
#[serde(default)]
pub rules: Vec<Rule>,
pub rules: Rules,
/// Valid ipfs hash for Ad Unit object. It will be used as fallback data (optional)
#[serde(default)]
pub fallback_unit: Option<IPFS>,
/// User address from the session
/// The AdSlot owner (Publisher)
pub owner: ValidatorId,
/// UTC timestamp in milliseconds, used as nonce for escaping duplicated spec ipfs hashes
#[serde(with = "ts_milliseconds")]
pub created: DateTime<Utc>,
/// the name of the unit used in platform UI
/// The name of the unit used in platform UI
#[serde(default)]
pub title: Option<String>,
/// arbitrary text used in platform UI
Expand Down
3 changes: 3 additions & 0 deletions primitives/src/campaign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,13 @@ mod pricing {

#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
pub struct Pricing {
/// The minimum payable amount for a single event
pub min: UnifiedNum,
/// The maximum payable amount for a single event
pub max: UnifiedNum,
}

/// The pricing bounds (minimum and maximum payable amount) per event type for 1 event.
#[derive(Default, Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
#[serde(transparent)]
pub struct PricingBounds(HashMap<EventType, Pricing>);
Expand Down
1 change: 1 addition & 0 deletions primitives/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ pub struct Config {
#[serde(rename = "chain")]
pub chains: HashMap<String, ChainInfo>,
pub platform: PlatformConfig,
/// Any limits applied to Sentry or Validator.
pub limits: Limits,
}

Expand Down
1 change: 0 additions & 1 deletion primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ pub mod merkle_tree;
pub mod platform;
pub mod sentry;
pub mod spender;
pub mod supermarket;
pub mod targeting;
// It's not possible to enable this feature for doctest,
// so we always must pass `--feature=test-util` or `--all-features` when running doctests:
Expand Down
36 changes: 24 additions & 12 deletions primitives/src/platform.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
pub use ad_unit::{AdUnitResponse, AdUnitsResponse};
use serde::{Deserialize, Serialize};
use url::Url;

mod ad_unit {
use crate::AdUnit;
use serde::{Deserialize, Serialize};
use crate::{AdSlot, AdUnit};

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct AdUnitsResponse(pub Vec<AdUnit>);
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Website {
#[serde(default)]
pub categories: Vec<String>,
#[serde(default)]
pub accepted_referrers: Vec<Url>,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct AdUnitResponse {
pub unit: AdUnit,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AdSlotResponse {
pub slot: AdSlot,
/// The fetched Fallback [`AdUnit`] ( [`AdSlot.fallback_unit`] ) of the [`AdSlot`] if set.
///
/// [`AdSlot.fallback_unit`]: AdSlot::fallback_unit
#[serde(default)]
pub fallback: Option<AdUnit>,
/// The [`AdSlot.website`] information if it's provided and information is available for it.
///
/// [`AdSlot.website`]: AdSlot::website
#[serde(default, flatten)]
pub website: Option<Website>,
}
67 changes: 67 additions & 0 deletions primitives/src/sentry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,73 @@ pub mod campaign_modify {
}
}

pub mod units_for_slot {
use std::collections::HashSet;

use serde::{Deserialize, Serialize};

use crate::Address;

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct Query {
#[serde(default)]
pub deposit_assets: HashSet<Address>,
}

pub mod response {
use serde::{Deserialize, Serialize};
use url::Url;

use crate::{targeting::Input, UnifiedNum, IPFS};

#[derive(Debug, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct Response {
pub targeting_input_base: Input,
pub accepted_referrers: Vec<Url>,
pub fallback_unit: Option<AdUnit>,
pub campaigns: Vec<Campaign>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct UnitsWithPrice {
pub unit: AdUnit,
pub price: UnifiedNum,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct Campaign {
#[serde(flatten)]
pub campaign: crate::Campaign,
/// units-for-slot Specific Campaign field
pub units_with_price: Vec<UnitsWithPrice>,
}

#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct AdUnit {
pub ipfs: IPFS,
pub media_url: String,
pub media_mime: String,
pub target_url: String,
}

impl From<&crate::AdUnit> for AdUnit {
fn from(ad_unit: &crate::AdUnit) -> Self {
Self {
ipfs: ad_unit.ipfs,
media_url: ad_unit.media_url.clone(),
media_mime: ad_unit.media_mime.clone(),
target_url: ad_unit.target_url.clone(),
}
}
}
}
}

#[cfg(feature = "postgres")]
mod postgres {
use bytes::BytesMut;
Expand Down
Loading