1
1
use std:: convert:: TryFrom ;
2
2
3
3
use chrono:: { DateTime , Utc } ;
4
+ use chrono:: serde:: ts_milliseconds;
4
5
use serde:: { Deserialize , Serialize } ;
5
6
use serde_hex:: { SerHex , StrictPfx } ;
6
7
7
- use crate :: domain:: { Asset , DomainError , RepositoryFuture , ValidatorDesc } ;
8
+ use crate :: domain:: { AdUnit , Asset , DomainError , EventSubmission , RepositoryFuture , TargetingTag , ValidatorDesc } ;
8
9
use crate :: domain:: bignum:: BigNum ;
10
+ use crate :: util:: serde:: ts_milliseconds_option;
9
11
10
12
#[ derive( Serialize , Deserialize , PartialEq , Eq , Debug , Copy , Clone ) ]
11
13
#[ serde( transparent) ]
@@ -55,6 +57,7 @@ pub struct Channel {
55
57
pub creator : String ,
56
58
pub deposit_asset : Asset ,
57
59
pub deposit_amount : BigNum ,
60
+ #[ serde( with = "ts_milliseconds" ) ]
58
61
pub valid_until : DateTime < Utc > ,
59
62
pub spec : ChannelSpec ,
60
63
}
@@ -63,7 +66,40 @@ pub struct Channel {
63
66
#[ serde( rename_all = "camelCase" ) ]
64
67
pub struct ChannelSpec {
65
68
// TODO: Add the rest of the fields Issue #24
69
+ #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
70
+ pub title : Option < String > ,
71
+ // TODO: Make a custom ser/deser 2 validators(leader, follower) array
66
72
pub validators : Vec < ValidatorDesc > ,
73
+ /// Maximum payment per impression
74
+ pub max_per_impression : BigNum ,
75
+ /// Minimum payment offered per impression
76
+ pub min_per_impression : BigNum ,
77
+ /// An array of TargetingTag (optional)
78
+ #[ serde( default , skip_serializing_if = "Vec::is_empty" ) ]
79
+ pub targeting : Vec < TargetingTag > ,
80
+ /// Minimum targeting score (optional)
81
+ #[ serde( default , skip_serializing_if = "Option::is_none" ) ]
82
+ pub min_targeting_score : Option < u64 > ,
83
+ /// EventSubmission object, applies to event submission (POST /channel/:id/events)
84
+ pub event_submission : EventSubmission ,
85
+ /// A millisecond timestamp of when the campaign was created
86
+ #[ serde( with = "ts_milliseconds" ) ]
87
+ pub created : DateTime < Utc > ,
88
+ /// A millisecond timestamp representing the time you want this campaign to become active (optional)
89
+ /// Used by the AdViewManager
90
+ #[ serde( default , skip_serializing_if = "Option::is_none" , with = "ts_milliseconds_option" ) ]
91
+ pub active_from : Option < DateTime < Utc > > ,
92
+ /// A random number to ensure the campaignSpec hash is unique
93
+ pub nonce : BigNum ,
94
+ /// A millisecond timestamp of when the campaign should enter a withdraw period
95
+ /// (no longer accept any events other than CHANNEL_CLOSE)
96
+ /// A sane value should be lower than channel.validUntil * 1000 and higher than created
97
+ /// It's recommended to set this at least one month prior to channel.validUntil * 1000
98
+ #[ serde( with = "ts_milliseconds" ) ]
99
+ pub withdraw_period_start : DateTime < Utc > ,
100
+ /// An array of AdUnit (optional)
101
+ #[ serde( default , skip_serializing_if = "Vec::is_empty" ) ]
102
+ pub ad_units : Vec < AdUnit > ,
67
103
}
68
104
69
105
pub struct ChannelListParams {
@@ -91,12 +127,9 @@ impl ChannelListParams {
91
127
}
92
128
93
129
let validator = validator
94
- . and_then ( |s| {
95
- if s. is_empty ( ) {
96
- return None ;
97
- }
98
-
99
- Some ( s)
130
+ . and_then ( |s| match s. is_empty ( ) {
131
+ true => None ,
132
+ false => Some ( s) ,
100
133
} ) ;
101
134
102
135
Ok ( Self {
0 commit comments