Skip to content

Commit 7fd8a4b

Browse files
committed
More changes regarding IPFS
1 parent 7bfa1c1 commit 7fd8a4b

File tree

4 files changed

+25
-27
lines changed

4 files changed

+25
-27
lines changed

adview-manager/src/lib.rs

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use adex_primitives::{
55
supermarket::units_for_slot,
66
supermarket::units_for_slot::response::{AdUnit, Campaign},
77
targeting::{self, input, Value},
8-
BigNum, ChannelId, SpecValidators, IPFS,
8+
BigNum, ChannelId, SpecValidators, ValidatorId, IPFS,
99
};
1010
use async_std::{sync::RwLock, task::block_on};
1111
use chrono::{DateTime, Utc};
@@ -42,17 +42,13 @@ lazy_static! {
4242

4343
#[derive(Serialize, Deserialize)]
4444
#[serde(rename_all = "camelCase")]
45-
// const defaultOpts = {
46-
// marketURL: 'https://market.moonicorn.network',
47-
// whitelistedTokens: ['0x6B175474E89094C44Da98b954EedeAC495271d0F'],
48-
// disableVideo: false,
49-
// }
45+
// TODO: Add Default Ops somehow?
5046
pub struct Options {
5147
// Defaulted via defaultOpts
5248
#[serde(rename = "marketURL")]
53-
pub market_url: String,
49+
pub market_url: Url,
5450
pub market_slot: IPFS,
55-
pub publisher_addr: String,
51+
pub publisher_addr: ValidatorId,
5652
// All passed tokens must be of the same price and decimals, so that the amounts can be accurately compared
5753
pub whitelisted_tokens: Vec<String>,
5854
pub width: Option<u64>,
@@ -83,7 +79,7 @@ pub struct HistoryEntry {
8379
struct Event {
8480
#[serde(rename = "type")]
8581
event_type: String,
86-
publisher: String,
82+
publisher: ValidatorId,
8783
ad_unit: IPFS,
8884
ad_slot: IPFS,
8985
#[serde(rename = "ref")]
@@ -156,7 +152,7 @@ fn is_video(ad_unit: &AdUnit) -> bool {
156152
ad_unit.media_mime.split('/').next() == Some("video")
157153
}
158154

159-
/// Does not copy the JS impl, instead it generates the BigNum from the IPFS CID bytes instead
155+
/// Does not copy the JS impl, instead it generates the BigNum from the IPFS CID bytes
160156
fn randomized_sort_pos(ad_unit: &AdUnit, seed: BigNum) -> BigNum {
161157
let bytes = ad_unit.id.0.to_bytes();
162158

@@ -220,7 +216,7 @@ pub fn get_unit_html_with_events(
220216
let get_body = |event_type: &str| EventBody {
221217
events: vec![Event {
222218
event_type: event_type.to_string(),
223-
publisher: options.publisher_addr.clone(),
219+
publisher: options.publisher_addr,
224220
ad_unit: ad_unit.id.clone(),
225221
ad_slot: options.market_slot.clone(),
226222
referrer: "document.referrer".to_string(),
@@ -405,13 +401,7 @@ impl Manager {
405401
pub async fn get_market_demand_resp(
406402
&self,
407403
) -> Result<units_for_slot::response::Response, Error> {
408-
let pub_prefix: String = self
409-
.options
410-
.publisher_addr
411-
.chars()
412-
.skip(2)
413-
.take(10)
414-
.collect();
404+
let pub_prefix: String = self.options.publisher_addr.to_hex_non_prefix_string();
415405

416406
let deposit_asset = self
417407
.options
@@ -421,8 +411,10 @@ impl Manager {
421411
.collect::<Vec<_>>()
422412
.join("&");
423413

414+
415+
// Url adds a trailing `/`
424416
let url = format!(
425-
"{}/units-for-slot/{}?pubPrefix={}&{}",
417+
"{}units-for-slot/{}?pubPrefix={}&{}",
426418
self.options.market_url, self.options.market_slot, pub_prefix, deposit_asset
427419
);
428420

@@ -562,7 +554,7 @@ impl Manager {
562554
None
563555
}
564556
})
565-
// TODO: Check what should happen here
557+
// TODO: Check what should happen here if we don't find the Validator
566558
.unwrap();
567559

568560
let html = get_unit_html_with_events(

primitives/src/targeting.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ pub mod input {
4343
match key {
4444
"adUnitId" => {
4545
let ipfs = self.ad_unit.as_ref().map(|ad_unit| ad_unit.id.clone());
46-
Ok(Value::String(ipfs.map(|ipfs| ipfs.to_string()).unwrap_or_default()))
46+
Ok(Value::String(
47+
ipfs.map(|ipfs| ipfs.to_string()).unwrap_or_default(),
48+
))
4749
}
4850

4951
"advertiserId" if channel.is_some() => {
@@ -338,7 +340,7 @@ pub mod input {
338340
.as_ref()
339341
.map(|ad_unit| ad_unit.ipfs.to_string());
340342

341-
Ok(Value::String(ipfs.unwrap_or_default()))
343+
Ok(Value::String(ipfs.unwrap_or_default()))
342344
}
343345
"advertiserId" => self
344346
.global
@@ -462,7 +464,7 @@ pub mod input {
462464
#[cfg(test)]
463465
mod test {
464466
use super::*;
465-
use crate::util::tests::prep_db::{DUMMY_CHANNEL, IDS, DUMMY_IPFS};
467+
use crate::util::tests::prep_db::{DUMMY_CHANNEL, DUMMY_IPFS, IDS};
466468
use chrono::Utc;
467469

468470
#[test]

primitives/src/targeting/eval_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::*;
22
use crate::{
33
targeting::input,
4-
util::tests::prep_db::{DUMMY_CHANNEL, IDS, DUMMY_IPFS},
4+
util::tests::prep_db::{DUMMY_CHANNEL, DUMMY_IPFS, IDS},
55
AdUnit, BalancesMap,
66
};
77
use chrono::Utc;

sentry/src/payout.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,13 @@ pub fn get_payout(logger: &Logger, channel: &Channel, event: &Event, session: &S
4040
if targeting_rules.is_empty() {
4141
Ok(Some((*publisher, pricing.min)))
4242
} else {
43-
let ad_unit = ad_unit
44-
.as_ref()
45-
.and_then(|ipfs| channel.spec.ad_units.iter().find(|u| &u.ipfs.to_string() == ipfs));
43+
let ad_unit = ad_unit.as_ref().and_then(|ipfs| {
44+
channel
45+
.spec
46+
.ad_units
47+
.iter()
48+
.find(|u| &u.ipfs.to_string() == ipfs)
49+
});
4650

4751
let source = input::Source {
4852
ad_view: None,

0 commit comments

Comments
 (0)