File tree Expand file tree Collapse file tree 5 files changed +50
-12
lines changed Expand file tree Collapse file tree 5 files changed +50
-12
lines changed Original file line number Diff line number Diff line change @@ -87,12 +87,12 @@ impl TryFrom<&Channel> for EthereumChannel {
87
87
hash. input ( spec) ;
88
88
let spec_hash: [ u8 ; 32 ] = hash. result ( ) . into ( ) ;
89
89
90
- let validators: Vec < ValidatorId > = channel
90
+ let validators = channel
91
91
. spec
92
92
. validators
93
- . into_iter ( )
94
- . map ( |v| v. id . clone ( ) )
95
- . collect ( ) ;
93
+ . iter ( )
94
+ . map ( |v| & v. id )
95
+ . collect :: < Vec < _ > > ( ) ;
96
96
97
97
let creator = <[ u8 ; 20 ] >:: from_hex ( & channel. creator [ 2 ..] )
98
98
. map_err ( |_| ChannelError :: InvalidArgument ( "failed to parse creator" . into ( ) ) ) ?;
@@ -104,7 +104,7 @@ impl TryFrom<&Channel> for EthereumChannel {
104
104
& deposit_asset,
105
105
& channel. deposit_amount . to_string ( ) ,
106
106
channel. valid_until ,
107
- & validators. as_slice ( ) ,
107
+ & validators,
108
108
& spec_hash,
109
109
)
110
110
}
@@ -116,7 +116,7 @@ impl EthereumChannel {
116
116
token_addr : & [ u8 ; 20 ] ,
117
117
token_amount : & str , // big num string
118
118
valid_until : DateTime < Utc > ,
119
- validators : & [ ValidatorId ] ,
119
+ validators : & [ & ValidatorId ] ,
120
120
spec : & [ u8 ; 32 ] ,
121
121
) -> Result < Self , ChannelError > {
122
122
if BigNum :: try_from ( token_amount) . is_err ( ) {
Original file line number Diff line number Diff line change @@ -234,7 +234,7 @@ pub fn get_html(
234
234
} ] ,
235
235
} ;
236
236
237
- let on_load: String = validators. into_iter ( ) . map ( |validator| {
237
+ let on_load: String = validators. iter ( ) . map ( |validator| {
238
238
let fetch_opts = "{ method: 'POST', headers: { 'content-type': 'application/json' }, body: this.dataset.eventBody }" ;
239
239
let fetch_url = format ! ( "{}/channel/{}/events" , validator. url, channel_id) ;
240
240
Original file line number Diff line number Diff line change @@ -148,6 +148,10 @@ impl SpecValidators {
148
148
SpecValidator :: None
149
149
}
150
150
}
151
+
152
+ pub fn iter ( & self ) -> Iter < ' _ > {
153
+ Iter :: new ( & self )
154
+ }
151
155
}
152
156
153
157
impl From < ( ValidatorDesc , ValidatorDesc ) > for SpecValidators {
@@ -159,10 +163,44 @@ impl From<(ValidatorDesc, ValidatorDesc)> for SpecValidators {
159
163
/// Fixed size iterator of 2, as we need an iterator in couple of occasions
160
164
impl < ' a > IntoIterator for & ' a SpecValidators {
161
165
type Item = & ' a ValidatorDesc ;
162
- type IntoIter = :: std :: vec :: IntoIter < Self :: Item > ;
166
+ type IntoIter = Iter < ' a > ;
163
167
164
168
fn into_iter ( self ) -> Self :: IntoIter {
165
- vec ! [ self . leader( ) , self . follower( ) ] . into_iter ( )
169
+ self . iter ( )
170
+ }
171
+ }
172
+
173
+ pub struct Iter < ' a > {
174
+ validators : & ' a SpecValidators ,
175
+ index : u8 ,
176
+ }
177
+
178
+ impl < ' a > Iter < ' a > {
179
+ fn new ( validators : & ' a SpecValidators ) -> Self {
180
+ Self {
181
+ validators,
182
+ index : 0 ,
183
+ }
184
+ }
185
+ }
186
+
187
+ impl < ' a > Iterator for Iter < ' a > {
188
+ type Item = & ' a ValidatorDesc ;
189
+
190
+ fn next ( & mut self ) -> Option < Self :: Item > {
191
+ match self . index {
192
+ 0 => {
193
+ self . index += 1 ;
194
+
195
+ Some ( self . validators . leader ( ) )
196
+ }
197
+ 1 => {
198
+ self . index += 1 ;
199
+
200
+ Some ( self . validators . follower ( ) )
201
+ }
202
+ _ => None ,
203
+ }
166
204
}
167
205
}
168
206
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ pub fn get_balances_after_fees_tree(
10
10
11
11
let total_distributed = balances. iter ( ) . map ( |( _, balance) | balance) . sum :: < BigNum > ( ) ;
12
12
13
- let validators_iter = channel. spec . validators . into_iter ( ) ;
13
+ let validators_iter = channel. spec . validators . iter ( ) ;
14
14
let total_validators_fee = validators_iter
15
15
. map ( |validator| & validator. fee )
16
16
. sum :: < BigNum > ( ) ;
@@ -54,7 +54,7 @@ pub fn get_balances_after_fees_tree(
54
54
balances_after_fees,
55
55
rounding_error,
56
56
fee_ratio,
57
- channel. spec . validators . into_iter ( ) ,
57
+ channel. spec . validators . iter ( ) ,
58
58
) ;
59
59
60
60
Ok ( balances_after_fees)
Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ impl<T: Adapter + 'static> SentryApi<T> {
46
46
let propagate_to = channel
47
47
. spec
48
48
. validators
49
- . into_iter ( )
49
+ . iter ( )
50
50
. map ( |validator| {
51
51
adapter
52
52
. get_auth ( & validator. id )
You can’t perform that action at this time.
0 commit comments