Skip to content

Commit b81584b

Browse files
committed
Merge branch 'aip-61-adex-v5' into issue-382-campaign-routes
2 parents 2d73644 + 5ed4c43 commit b81584b

23 files changed

+737
-1156
lines changed

Cargo.lock

Lines changed: 236 additions & 516 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

adapter/Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ serde = { version = "^1.0", features = ['derive'] }
1717
serde_json = "1.0"
1818
serde-hex = "0.1.0"
1919
# Ethereum
20-
web3 = { version = "0.15", features = ["http-tls", "signing"] }
20+
web3 = { version = "0.16", features = ["http-tls", "signing"] }
2121
eth_checksum = "0.1"
2222
tiny-keccak = "1.5"
2323
ethstore = { git = "https://github.com/openethereum/openethereum", tag = "v3.1.1-rc.1" }
@@ -26,11 +26,11 @@ create2 = "0.0.2"
2626
# API client
2727
reqwest = { version = "0.11", features = ["json"] }
2828

29-
sha2 = "0.8.0"
30-
base64 = "0.10.1"
29+
sha2 = "0.9"
30+
base64 = "0.13"
3131
lazy_static = "^1.4"
3232
# Futures
33-
futures = { version = "0.3", features = ["compat"] }
33+
futures = "0.3"
3434
async-trait = "0.1"
3535
tokio-compat-02 = "0.2"
3636

@@ -40,4 +40,4 @@ dashmap = "4.0"
4040
[dev-dependencies]
4141
byteorder = "^1.4"
4242
tokio = { version = "^1", features = ["macros", "rt-multi-thread"] }
43-
wiremock = "0.4"
43+
wiremock = "0.5"

adapter/src/ethereum.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,8 @@ impl Adapter for EthereumAdapter {
293293
let sweeper_address = sweeper_contract.address();
294294
let outpace_address = outpace_contract.address();
295295

296-
let on_outpace: U256 = tokio_compat_02::FutureExt::compat(async {
297-
tokio_compat_02::FutureExt::compat(outpace_contract.query(
296+
let on_outpace: U256 = outpace_contract
297+
.query(
298298
"deposits",
299299
(
300300
Token::FixedBytes(channel.id().as_bytes().to_vec()),
@@ -303,11 +303,9 @@ impl Adapter for EthereumAdapter {
303303
None,
304304
Options::default(),
305305
None,
306-
))
306+
)
307307
.await
308-
})
309-
.await
310-
.map_err(Error::ContractQuerying)?;
308+
.map_err(Error::ContractQuerying)?;
311309

312310
let on_outpace = BigNum::from_str(&on_outpace.to_string())?;
313311

@@ -317,18 +315,16 @@ impl Adapter for EthereumAdapter {
317315
outpace_address,
318316
depositor_address,
319317
);
320-
let still_on_create2: U256 = tokio_compat_02::FutureExt::compat(async {
321-
tokio_compat_02::FutureExt::compat(erc20_contract.query(
318+
let still_on_create2: U256 = erc20_contract
319+
.query(
322320
"balanceOf",
323321
counterfactual_address,
324322
None,
325323
Options::default(),
326324
None,
327-
))
325+
)
328326
.await
329-
})
330-
.await
331-
.map_err(Error::ContractQuerying)?;
327+
.map_err(Error::ContractQuerying)?;
332328

333329
let still_on_create2: BigNum = still_on_create2.to_string().parse()?;
334330

adview-manager/src/lib.rs

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
#![deny(clippy::all)]
33

44
use adex_primitives::{
5+
campaign::Validators,
56
supermarket::units_for_slot,
67
supermarket::units_for_slot::response::{AdUnit, Campaign},
78
targeting::{self, input},
8-
BigNum, ChannelId, SpecValidators, ValidatorId, IPFS,
9+
Address, BigNum, CampaignId, ToHex, UnifiedNum, IPFS,
910
};
1011
use async_std::{sync::RwLock, task::block_on};
1112
use chrono::{DateTime, Utc};
@@ -23,7 +24,6 @@ use std::{
2324
sync::Arc,
2425
};
2526
use thiserror::Error;
26-
use units_for_slot::response::UnitsWithPrice;
2727
use url::Url;
2828

2929
const IPFS_GATEWAY: &str = "https://ipfs.moonicorn.network/ipfs/";
@@ -48,7 +48,7 @@ pub struct Options {
4848
#[serde(rename = "marketURL")]
4949
pub market_url: Url,
5050
pub market_slot: IPFS,
51-
pub publisher_addr: ValidatorId,
51+
pub publisher_addr: Address,
5252
// All passed tokens must be of the same price and decimals, so that the amounts can be accurately compared
5353
pub whitelisted_tokens: Vec<String>,
5454
pub width: Option<u64>,
@@ -70,7 +70,7 @@ impl Options {
7070
pub struct HistoryEntry {
7171
time: DateTime<Utc>,
7272
unit_id: IPFS,
73-
campaign_id: ChannelId,
73+
campaign_id: CampaignId,
7474
slot_id: IPFS,
7575
}
7676

@@ -79,7 +79,7 @@ pub struct HistoryEntry {
7979
struct Event {
8080
#[serde(rename = "type")]
8181
event_type: String,
82-
publisher: ValidatorId,
82+
publisher: Address,
8383
ad_unit: IPFS,
8484
ad_slot: IPFS,
8585
#[serde(rename = "ref")]
@@ -209,16 +209,16 @@ pub fn get_unit_html_with_events(
209209
options: &Options,
210210
ad_unit: &AdUnit,
211211
hostname: &str,
212-
channel_id: ChannelId,
213-
validators: &SpecValidators,
212+
campaign_id: CampaignId,
213+
validators: &Validators,
214214
no_impression: impl Into<bool>,
215215
) -> String {
216216
let get_body = |event_type: &str| EventBody {
217217
events: vec![Event {
218218
event_type: event_type.to_string(),
219219
publisher: options.publisher_addr,
220-
ad_unit: ad_unit.id.clone(),
221-
ad_slot: options.market_slot.clone(),
220+
ad_unit: ad_unit.id,
221+
ad_slot: options.market_slot,
222222
referrer: "document.referrer".to_string(),
223223
}],
224224
};
@@ -234,7 +234,7 @@ pub fn get_unit_html_with_events(
234234
.map(|validator| {
235235
let fetch_url = format!(
236236
"{}/channel/{}/events?pubAddr={}",
237-
validator.url, channel_id, options.publisher_addr
237+
validator.url, campaign_id, options.publisher_addr
238238
);
239239

240240
format!("fetch('{}', fetchOpts)", fetch_url)
@@ -304,7 +304,7 @@ impl Manager {
304304
pub async fn get_targeting_input(
305305
&self,
306306
mut input: input::Input,
307-
channel_id: ChannelId,
307+
campaign_id: CampaignId,
308308
) -> input::Input {
309309
let seconds_since_campaign_impression = self
310310
.history
@@ -313,7 +313,7 @@ impl Manager {
313313
.iter()
314314
.rev()
315315
.find_map(|h| {
316-
if h.campaign_id == channel_id {
316+
if h.campaign_id == campaign_id {
317317
let last_impression: chrono::Duration = Utc::now() - h.time;
318318

319319
u64::try_from(last_impression.num_seconds()).ok()
@@ -352,7 +352,7 @@ impl Manager {
352352

353353
let stick_campaign = campaigns
354354
.iter()
355-
.find(|c| c.channel.id == sticky_entry.campaign_id)?;
355+
.find(|c| c.campaign.id == sticky_entry.campaign_id)?;
356356

357357
let unit = stick_campaign
358358
.units_with_price
@@ -370,8 +370,8 @@ impl Manager {
370370
&self.options,
371371
&unit,
372372
hostname,
373-
stick_campaign.channel.id,
374-
&stick_campaign.channel.spec.validators,
373+
stick_campaign.campaign.id,
374+
&stick_campaign.campaign.validators,
375375
true,
376376
);
377377

@@ -383,7 +383,7 @@ impl Manager {
383383
})
384384
}
385385

386-
async fn is_campaign_sticky(&self, campaign_id: ChannelId) -> bool {
386+
async fn is_campaign_sticky(&self, campaign_id: CampaignId) -> bool {
387387
if self.options.disabled_sticky {
388388
false
389389
} else {
@@ -400,7 +400,7 @@ impl Manager {
400400
pub async fn get_market_demand_resp(
401401
&self,
402402
) -> Result<units_for_slot::response::Response, Error> {
403-
let pub_prefix: String = self.options.publisher_addr.to_hex_non_prefix_string();
403+
let pub_prefix = self.options.publisher_addr.to_hex();
404404

405405
let deposit_asset = self
406406
.options
@@ -432,7 +432,7 @@ impl Manager {
432432

433433
pub async fn get_next_ad_unit(&self) -> Result<Option<NextAdUnit>, Error> {
434434
let units_for_slot = self.get_market_demand_resp().await?;
435-
let campaigns = &units_for_slot.campaigns;
435+
let m_campaigns = &units_for_slot.campaigns;
436436
let fallback_unit = units_for_slot.fallback_unit;
437437
let targeting_input = units_for_slot.targeting_input_base;
438438

@@ -444,7 +444,7 @@ impl Manager {
444444

445445
// Stickiness is when we keep showing an ad unit for a slot for some time in order to achieve fair impression value
446446
// see https://github.com/AdExNetwork/adex-adview-manager/issues/65
447-
let sticky_result = self.get_sticky_ad_unit(campaigns, &hostname).await;
447+
let sticky_result = self.get_sticky_ad_unit(m_campaigns, &hostname).await;
448448
if let Some(sticky) = sticky_result {
449449
return Ok(Some(NextAdUnit {
450450
unit: sticky.unit,
@@ -461,36 +461,36 @@ impl Manager {
461461
let seed = BigNum::from(random as u64);
462462

463463
// Apply targeting, now with adView.* variables, and sort the resulting ad units
464-
let mut units_with_price: Vec<(UnitsWithPrice, ChannelId)> = campaigns
464+
let mut units_with_price = m_campaigns
465465
.iter()
466-
.map(|campaign| {
466+
.map(|m_campaign| {
467467
// since we are in a Iterator.map(), we can't use async, so we block
468-
if block_on(self.is_campaign_sticky(campaign.channel.id)) {
468+
if block_on(self.is_campaign_sticky(m_campaign.campaign.id)) {
469469
return vec![];
470470
}
471471

472-
let campaign_id = campaign.channel.id;
472+
let campaign_id = m_campaign.campaign.id;
473473

474-
let mut unit_input = targeting_input.clone().with_market_channel(campaign.channel.clone());
474+
let mut unit_input = targeting_input.clone().with_campaign(m_campaign.campaign.clone());
475475

476-
campaign
476+
m_campaign
477477
.units_with_price
478478
.iter()
479479
.filter(|unit_with_price| {
480-
unit_input.ad_unit_id = Some(unit_with_price.unit.id.clone());
480+
unit_input.ad_unit_id = Some(unit_with_price.unit.id);
481481

482482
let mut output = targeting::Output {
483483
show: true,
484484
boost: 1.0,
485-
price: vec![("IMPRESSION".to_string(), unit_with_price.price.clone())]
485+
price: vec![("IMPRESSION".to_string(), unit_with_price.price)]
486486
.into_iter()
487487
.collect(),
488488
};
489489

490490
let on_type_error = |error, rule| error!(&self.logger, "Rule evaluation error for {:?}", campaign_id; "error" => ?error, "rule" => ?rule);
491491

492492
targeting::eval_with_callback(
493-
&campaign.targeting_rules,
493+
&m_campaign.campaign.targeting_rules,
494494
&unit_input,
495495
&mut output,
496496
Some(on_type_error)
@@ -503,7 +503,7 @@ impl Manager {
503503
})
504504
.flatten()
505505
.filter(|x| !(self.options.disabled_video && is_video(&x.0.unit)))
506-
.collect();
506+
.collect::<Vec<_>>();
507507

508508
units_with_price.sort_by(|b, a| match (&a.0.price).cmp(&b.0.price) {
509509
Ordering::Equal => randomized_sort_pos(&a.0.unit, seed.clone())
@@ -519,9 +519,9 @@ impl Manager {
519519

520520
let new_entry = HistoryEntry {
521521
time: Utc::now(),
522-
unit_id: unit_with_price.unit.id.clone(),
522+
unit_id: unit_with_price.unit.id,
523523
campaign_id: *campaign_id,
524-
slot_id: self.options.market_slot.clone(),
524+
slot_id: self.options.market_slot,
525525
};
526526

527527
*self.history.write().await = history
@@ -539,11 +539,11 @@ impl Manager {
539539

540540
// Return the results, with a fallback unit if there is one
541541
if let Some((unit_with_price, campaign_id)) = auction_winner {
542-
let validators = campaigns
542+
let validators = m_campaigns
543543
.iter()
544-
.find_map(|campaign| {
545-
if &campaign.channel.id == campaign_id {
546-
Some(&campaign.channel.spec.validators)
544+
.find_map(|m_campaign| {
545+
if &m_campaign.campaign.id == campaign_id {
546+
Some(&m_campaign.campaign.validators)
547547
} else {
548548
None
549549
}
@@ -562,7 +562,7 @@ impl Manager {
562562

563563
Ok(Some(NextAdUnit {
564564
unit: unit_with_price.unit.clone(),
565-
price: unit_with_price.price.clone(),
565+
price: unit_with_price.price,
566566
accepted_referrers: units_for_slot.accepted_referrers,
567567
html,
568568
}))
@@ -582,14 +582,14 @@ impl Manager {
582582

583583
pub struct NextAdUnit {
584584
pub unit: AdUnit,
585-
pub price: BigNum,
585+
pub price: UnifiedNum,
586586
pub accepted_referrers: Vec<Url>,
587587
pub html: String,
588588
}
589589

590590
pub struct StickyAdUnit {
591591
pub unit: AdUnit,
592-
pub price: BigNum,
592+
pub price: UnifiedNum,
593593
pub html: String,
594594
pub is_sticky: bool,
595595
}

primitives/Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ serde_json = "1.0"
1717
serde-hex = "0.1.0"
1818
serde_millis = "0.1.1"
1919
# Used prefixes on field for targeting::Input, and `campaign::Active`
20-
serde_with = "1.6"
20+
serde_with = "1.9"
2121
# Configuration
2222
toml = "0.5"
2323
# Logging
@@ -30,13 +30,13 @@ chrono = { version = "0.4", features = ["serde"] }
3030
time = "0.1.42"
3131
uuid = { version = "0.8", features = ["v4"] }
3232
# For encoding the Channel to a ChannelId
33-
ethabi = "13.0.0"
33+
ethabi = "14.0.0"
3434
# For the nonce U256
3535
ethereum-types = "0.11"
3636
# Macro for easier derive of Display & FromStr
37-
parse-display = "^0.4.1"
37+
parse-display = "^0.5.0"
3838
# CID & multihash / multibase
39-
cid = "0.6"
39+
cid = "0.7"
4040
hex = "0.4"
4141
merkletree = "0.10.0"
4242
tiny-keccak = { version = "^2.0", features = ["keccak"] }
@@ -60,8 +60,8 @@ async-trait = "0.1"
6060
lazy_static = "1.4.0"
6161

6262
[dev-dependencies]
63-
pretty_assertions = "^0.6"
63+
pretty_assertions = "^0.7"
6464
# testing FromSql & ToSql implementation of structs
65-
deadpool-postgres = "0.7.0"
65+
deadpool-postgres = "0.9.0"
6666
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
6767
once_cell = "1.5"

primitives/src/balances_map.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ mod test {
109109

110110
let actual_json = serde_json::to_value(&unified_map).expect("Should serialize it");
111111
let expected_json = json!({
112-
"0xC91763D7F14ac5c5dDfBCD012e0D2A61ab9bDED3":100,
113-
"0xce07CbB7e054514D590a0262C93070D838bFBA2e":50
112+
"0xC91763D7F14ac5c5dDfBCD012e0D2A61ab9bDED3":"100",
113+
"0xce07CbB7e054514D590a0262C93070D838bFBA2e":"50"
114114
});
115115

116116
assert_eq!(expected_json, actual_json);

0 commit comments

Comments
 (0)