@@ -39,3 +39,100 @@ pub enum Finalized {
39
39
Exhausted ,
40
40
Withdraw ,
41
41
}
42
+
43
+ pub mod units_for_slot {
44
+ pub mod response {
45
+ use chrono:: {
46
+ serde:: { ts_milliseconds, ts_milliseconds_option} ,
47
+ DateTime , Utc ,
48
+ } ;
49
+ use crate :: { targeting:: Rule , BigNum , ChannelId , SpecValidators , ValidatorId , ChannelSpec } ;
50
+ use serde:: Serialize ;
51
+
52
+ #[ derive( Debug , Serialize ) ]
53
+ #[ serde( rename_all = "camelCase" ) ]
54
+ pub struct UnitsWithPrice {
55
+ pub unit : AdUnit ,
56
+ pub price : BigNum ,
57
+ }
58
+
59
+ #[ derive( Debug , Serialize ) ]
60
+ #[ serde( rename_all = "camelCase" ) ]
61
+ pub struct Campaign {
62
+ #[ serde( flatten) ]
63
+ pub channel : Channel ,
64
+ pub targeting_rules : Vec < Rule > ,
65
+ pub units_with_price : Vec < UnitsWithPrice > ,
66
+ }
67
+
68
+ #[ derive( Debug , Serialize ) ]
69
+ #[ serde( rename_all = "camelCase" ) ]
70
+ pub struct Channel {
71
+ pub id : ChannelId ,
72
+ pub creator : ValidatorId ,
73
+ pub deposit_asset : String ,
74
+ pub deposit_amount : BigNum ,
75
+ pub spec : Spec ,
76
+ }
77
+
78
+ impl From < crate :: Channel > for Channel {
79
+ fn from ( channel : crate :: Channel ) -> Self {
80
+ Self {
81
+ id : channel. id ,
82
+ creator : channel. creator ,
83
+ deposit_asset : channel. deposit_asset ,
84
+ deposit_amount : channel. deposit_amount ,
85
+ spec : channel. spec . into ( ) ,
86
+ }
87
+ }
88
+ }
89
+
90
+ #[ derive( Debug , Serialize ) ]
91
+ #[ serde( rename_all = "camelCase" ) ]
92
+ pub struct Spec {
93
+ #[ serde( with = "ts_milliseconds" ) ]
94
+ pub withdraw_period_start : DateTime < Utc > ,
95
+ #[ serde(
96
+ default ,
97
+ skip_serializing_if = "Option::is_none" ,
98
+ with = "ts_milliseconds_option"
99
+ ) ]
100
+ pub active_from : Option < DateTime < Utc > > ,
101
+ #[ serde( with = "ts_milliseconds" ) ]
102
+ pub created : DateTime < Utc > ,
103
+ pub validators : SpecValidators ,
104
+ }
105
+
106
+ impl From < ChannelSpec > for Spec {
107
+ fn from ( channel_spec : ChannelSpec ) -> Self {
108
+ Self {
109
+ withdraw_period_start : channel_spec. withdraw_period_start ,
110
+ active_from : channel_spec. active_from ,
111
+ created : channel_spec. created ,
112
+ validators : channel_spec. validators ,
113
+ }
114
+ }
115
+ }
116
+
117
+ #[ derive( Debug , Serialize ) ]
118
+ #[ serde( rename_all = "camelCase" ) ]
119
+ pub struct AdUnit {
120
+ /// Same as `ipfs`
121
+ pub id : String ,
122
+ pub media_url : String ,
123
+ pub media_mime : String ,
124
+ pub target_url : String ,
125
+ }
126
+
127
+ impl From < crate :: AdUnit > for AdUnit {
128
+ fn from ( ad_unit : crate :: AdUnit ) -> Self {
129
+ Self {
130
+ id : ad_unit. ipfs ,
131
+ media_url : ad_unit. media_url ,
132
+ media_mime : ad_unit. media_mime ,
133
+ target_url : ad_unit. target_url ,
134
+ }
135
+ }
136
+ }
137
+ }
138
+ }
0 commit comments