1
1
#![ deny( rust_2018_idioms) ]
2
2
#![ deny( clippy:: all) ]
3
3
4
- use adex_primitives:: market_channel :: { MarketChannel , MarketStatusType } ;
5
- use adex_primitives:: { AdUnit , BigNum , SpecValidators , TargetingTag } ;
4
+ use adex_primitives:: market :: { Campaign , StatusType } ;
5
+ use adex_primitives:: { AdUnit , BigNum , ChannelId , SpecValidators , TargetingTag } ;
6
6
use chrono:: Utc ;
7
7
use serde:: { Deserialize , Serialize } ;
8
8
@@ -18,7 +18,7 @@ pub struct AdViewManagerOptions {
18
18
#[ serde( rename = "marketURL" ) ]
19
19
pub market_url : String ,
20
20
/// Defaulted
21
- pub accepted_states : Vec < MarketStatusType > ,
21
+ pub accepted_states : Vec < StatusType > ,
22
22
/// Defaulted
23
23
pub min_per_impression : BigNum ,
24
24
/// Defaulted
@@ -51,7 +51,7 @@ impl AdViewManagerOptions {
51
51
#[ derive( Debug ) ]
52
52
pub struct UnitByPrice {
53
53
pub unit : AdUnit ,
54
- pub channel_id : String ,
54
+ pub channel_id : ChannelId ,
55
55
pub validators : SpecValidators ,
56
56
pub min_targeting_score : MinTargetingScore ,
57
57
pub min_per_impression : BigNum ,
@@ -60,7 +60,7 @@ pub struct UnitByPrice {
60
60
#[ derive( Debug ) ]
61
61
pub struct Unit {
62
62
pub unit : AdUnit ,
63
- pub channel_id : String ,
63
+ pub channel_id : ChannelId ,
64
64
pub validators : SpecValidators ,
65
65
pub min_targeting_score : MinTargetingScore ,
66
66
pub min_per_impression : BigNum ,
@@ -80,24 +80,26 @@ impl Unit {
80
80
}
81
81
}
82
82
83
- pub fn apply_selection ( campaigns : & [ MarketChannel ] , options : & AdViewManagerOptions ) -> Vec < Unit > {
83
+ pub fn apply_selection ( campaigns : & [ Campaign ] , options : & AdViewManagerOptions ) -> Vec < Unit > {
84
84
let eligible = campaigns. iter ( ) . filter ( |campaign| {
85
85
options
86
86
. accepted_states
87
87
. contains ( & campaign. status . status_type )
88
88
&& campaign
89
+ . channel
89
90
. spec
90
91
. active_from
91
92
. map ( |datetime| datetime < Utc :: now ( ) )
92
93
. unwrap_or ( true )
93
- && campaign. deposit_asset == options. whitelisted_token
94
- && campaign. spec . min_per_impression >= options. min_per_impression
94
+ && campaign. channel . deposit_asset == options. whitelisted_token
95
+ && campaign. channel . spec . min_per_impression >= options. min_per_impression
95
96
} ) ;
96
97
97
98
let mut units: Vec < UnitByPrice > = eligible
98
99
// filter ad_units by whitelisted type, map then to UnitByPrice and flat_map them for each campaing
99
100
. flat_map ( |campaign| {
100
101
campaign
102
+ . channel
101
103
. spec
102
104
. ad_units
103
105
. iter ( )
@@ -113,13 +115,13 @@ pub fn apply_selection(campaigns: &[MarketChannel], options: &AdViewManagerOptio
113
115
} )
114
116
. map ( move |ad_unit| UnitByPrice {
115
117
unit : ad_unit. clone ( ) ,
116
- channel_id : campaign. id . clone ( ) ,
117
- validators : campaign. spec . validators . clone ( ) ,
118
+ channel_id : campaign. channel . id ,
119
+ validators : campaign. channel . spec . validators . clone ( ) ,
118
120
min_targeting_score : ad_unit
119
121
. min_targeting_score
120
- . or ( campaign. spec . min_targeting_score )
122
+ . or ( campaign. channel . spec . min_targeting_score )
121
123
. unwrap_or_else ( || 0 . into ( ) ) ,
122
- min_per_impression : campaign. spec . min_per_impression . clone ( ) ,
124
+ min_per_impression : campaign. channel . spec . min_per_impression . clone ( ) ,
123
125
} )
124
126
} )
125
127
. collect ( ) ;
@@ -223,7 +225,7 @@ fn video_html(
223
225
pub fn get_html (
224
226
options : & AdViewManagerOptions ,
225
227
ad_unit : AdUnit ,
226
- channel_id : & str ,
228
+ channel_id : ChannelId ,
227
229
validators : & SpecValidators ,
228
230
) -> String {
229
231
let ev_body = EventBody {
@@ -267,19 +269,19 @@ fn get_unit_html(
267
269
let adex_icon = "<a href=\" https://www.adex.network\" target=\" _blank\" rel=\" noopener noreferrer\"
268
270
style=\" position: absolute; top: 0; right: 0;\"
269
271
>
270
- <svg version=\" 1.1\" xmlns=\" http://www.w3.org/2000/svg\" xmlns:xlink=\" http://www.w3.org/1999/xlink\" x=\" 0px\" y=\" 0px\" width=\" 18px\"
271
- height=\" 18px\" viewBox=\" 0 0 18 18\" style=\" enable-background:new 0 0 18 18;\" xml:space=\" preserve\" >
272
- <style type=\" text/css\" >
273
- .st0{fill:#FFFFFF;}
274
- .st1{fill:#1B75BC;}
275
- </style>
276
- <defs>
277
- </defs>
278
- <rect class=\" st0\" width=\" 18\" height=\" 18\" />
279
- <path class=\" st1\" d=\" M14,12.1L10.9,9L14,5.9L12.1,4L9,7.1L5.9,4L4,5.9L7.1,9L4,12.1L5.9,14L9,10.9l3.1,3.1L14,12.1z M7.9,2L6.4,3.5
280
- L7.9,5L9,3.9L10.1,5l1.5-1.5L10,1.9l-1-1L7.9,2 M7.9,16l-1.5-1.5L7.9,13L9,14.1l1.1-1.1l1.5,1.5L10,16.1l-1,1L7.9,16\" />
281
- </svg>
282
- </a>";
272
+ <svg version=\" 1.1\" xmlns=\" http://www.w3.org/2000/svg\" xmlns:xlink=\" http://www.w3.org/1999/xlink\" x=\" 0px\" y=\" 0px\" width=\" 18px\"
273
+ height=\" 18px\" viewBox=\" 0 0 18 18\" style=\" enable-background:new 0 0 18 18;\" xml:space=\" preserve\" >
274
+ <style type=\" text/css\" >
275
+ .st0{fill:#FFFFFF;}
276
+ .st1{fill:#1B75BC;}
277
+ </style>
278
+ <defs>
279
+ </defs>
280
+ <rect class=\" st0\" width=\" 18\" height=\" 18\" />
281
+ <path class=\" st1\" d=\" M14,12.1L10.9,9L14,5.9L12.1,4L9,7.1L5.9,4L4,5.9L7.1,9L4,12.1L5.9,14L9,10.9l3.1,3.1L14,12.1z M7.9,2L6.4,3.5
282
+ L7.9,5L9,3.9L10.1,5l1.5-1.5L10,1.9l-1-1L7.9,2 M7.9,16l-1.5-1.5L7.9,13L9,14.1l1.1-1.1l1.5,1.5L10,16.1l-1,1L7.9,16\" />
283
+ </svg>
284
+ </a>";
283
285
284
286
let result = format ! ( "
285
287
<div style=\" position: relative; overflow: hidden; {size}\" >
@@ -294,8 +296,12 @@ fn get_unit_html(
294
296
#[ cfg( test) ]
295
297
mod test {
296
298
use super :: * ;
299
+ use adex_primitives:: ValidatorId ;
300
+ use std:: convert:: TryFrom ;
297
301
298
302
fn get_ad_unit ( media_mime : & str ) -> AdUnit {
303
+ let owner = ValidatorId :: try_from ( "0xce07CbB7e054514D590a0262C93070D838bFBA2e" )
304
+ . expect ( "Should be valid ValidatorId string" ) ;
299
305
AdUnit {
300
306
ipfs : "" . to_string ( ) ,
301
307
ad_type : "" . to_string ( ) ,
@@ -305,7 +311,7 @@ mod test {
305
311
targeting : vec ! [ ] ,
306
312
min_targeting_score : None ,
307
313
tags : vec ! [ ] ,
308
- owner : "" . to_string ( ) ,
314
+ owner,
309
315
created : Utc :: now ( ) ,
310
316
title : None ,
311
317
description : None ,
0 commit comments