@@ -15,7 +15,8 @@ use std::str::FromStr;
15
15
use structopt:: StructOpt ;
16
16
use thiserror:: Error ;
17
17
use thor:: cli:: { Alias , Connection } ;
18
- use valgrind:: { Proposal , ProposalExtension } ;
18
+ use valgrind:: ProposalExtension ;
19
+ use vit_servicing_station_lib:: db:: models:: proposals:: FullProposalInfo ;
19
20
use wallet_core:: Choice ;
20
21
21
22
///
@@ -136,6 +137,8 @@ pub struct Votes {
136
137
/// Print title, otherwise only id would be print out
137
138
#[ structopt( long = "print-title" ) ]
138
139
pub print_proposal_title : bool ,
140
+ #[ structopt( default_value = "direct" , long) ]
141
+ pub voting_group : String ,
139
142
}
140
143
141
144
impl Votes {
@@ -157,7 +160,7 @@ impl Votes {
157
160
let vote_plan_id_hash = Hash :: from_str ( & vote_plan_id) ?;
158
161
if self . print_proposal_title {
159
162
let history = model. vote_plan_history ( vote_plan_id_hash) ?;
160
- let proposals = model. proposals ( ) ?;
163
+ let proposals = model. proposals ( & self . voting_group ) ?;
161
164
162
165
if let Some ( history) = history {
163
166
let history: Vec < String > = history
@@ -166,12 +169,12 @@ impl Votes {
166
169
proposals
167
170
. iter ( )
168
171
. find ( |y| {
169
- y. chain_proposal_index as u8 == * x
170
- && y. chain_voteplan_id == vote_plan_id
172
+ y. voteplan . chain_proposal_index as u8 == * x
173
+ && y. voteplan . chain_voteplan_id == vote_plan_id
171
174
} )
172
175
. unwrap ( )
173
176
} )
174
- . map ( |p| p. proposal_title . clone ( ) )
177
+ . map ( |p| p. proposal . proposal_title . clone ( ) )
175
178
. collect ( ) ;
176
179
println ! ( "{:#?}" , history) ;
177
180
} else {
@@ -184,7 +187,7 @@ impl Votes {
184
187
None => {
185
188
if self . print_proposal_title {
186
189
let history = model. votes_history ( ) ?;
187
- let proposals = model. proposals ( ) ?;
190
+ let proposals = model. proposals ( & self . voting_group ) ?;
188
191
189
192
if let Some ( history) = history {
190
193
let history: Vec < String > = history
@@ -193,12 +196,13 @@ impl Votes {
193
196
proposals
194
197
. iter ( )
195
198
. find ( |y| {
196
- x. votes . contains ( & ( y. chain_proposal_index as u8 ) )
197
- && y. chain_voteplan_id == x. vote_plan_id . to_string ( )
199
+ x. votes . contains ( & ( y. voteplan . chain_proposal_index as u8 ) )
200
+ && y. voteplan . chain_voteplan_id
201
+ == x. vote_plan_id . to_string ( )
198
202
} )
199
203
. unwrap ( )
200
204
} )
201
- . map ( |p| p. proposal_title . clone ( ) )
205
+ . map ( |p| p. proposal . proposal_title . clone ( ) )
202
206
. collect ( ) ;
203
207
println ! ( "{:#?}" , history)
204
208
} else {
@@ -248,11 +252,13 @@ pub struct SingleVote {
248
252
/// Pin
249
253
#[ structopt( long, short) ]
250
254
pub pin : String ,
255
+ #[ structopt( default_value = "direct" , long) ]
256
+ pub voting_group : String ,
251
257
}
252
258
253
259
impl SingleVote {
254
260
pub fn exec ( self , mut model : CliController ) -> Result < ( ) , IapyxCommandError > {
255
- let proposals = model. proposals ( ) ?;
261
+ let proposals = model. proposals ( & self . voting_group ) ?;
256
262
/* let block_date_generator = expiry::from_block_or_shift(
257
263
self.valid_until_fixed,
258
264
self.valid_until_shift,
@@ -264,6 +270,7 @@ impl SingleVote {
264
270
. find ( |x| x. chain_proposal_id_as_str ( ) == self . proposal_id )
265
271
. ok_or_else ( || IapyxCommandError :: CannotFindProposal ( self . proposal_id . clone ( ) ) ) ?;
266
272
let choice = proposal
273
+ . proposal
267
274
. chain_vote_options
268
275
. 0
269
276
. get ( & self . choice )
@@ -288,12 +295,16 @@ pub struct BatchOfVotes {
288
295
/// Pin
289
296
#[ structopt( long, short) ]
290
297
pub pin : String ,
298
+ #[ structopt( default_value = "direct" , long) ]
299
+ pub voting_group : String ,
291
300
}
292
301
293
302
impl BatchOfVotes {
294
303
pub fn exec ( self , mut model : CliController ) -> Result < ( ) , IapyxCommandError > {
295
- let choices = self
296
- . zip_into_batch_input_data ( serde_json:: from_str ( & self . choices ) ?, model. proposals ( ) ?) ?;
304
+ let choices = self . zip_into_batch_input_data (
305
+ serde_json:: from_str ( & self . choices ) ?,
306
+ model. proposals ( & self . voting_group ) ?,
307
+ ) ?;
297
308
model. votes_batch ( choices. iter ( ) . map ( |( p, c) | ( p, * c) ) . collect ( ) , & self . pin ) ?;
298
309
model. save_config ( ) ?;
299
310
Ok ( ( ) )
@@ -302,8 +313,8 @@ impl BatchOfVotes {
302
313
fn zip_into_batch_input_data (
303
314
& self ,
304
315
choices : HashMap < String , String > ,
305
- proposals : Vec < Proposal > ,
306
- ) -> Result < Vec < ( Proposal , Choice ) > , IapyxCommandError > {
316
+ proposals : Vec < FullProposalInfo > ,
317
+ ) -> Result < Vec < ( FullProposalInfo , Choice ) > , IapyxCommandError > {
307
318
let mut result = Vec :: new ( ) ;
308
319
309
320
for ( proposal_id, choice) in choices {
@@ -313,6 +324,7 @@ impl BatchOfVotes {
313
324
. ok_or_else ( || IapyxCommandError :: CannotFindProposal ( proposal_id. clone ( ) ) ) ?;
314
325
315
326
let choice = proposal
327
+ . proposal
316
328
. chain_vote_options
317
329
. 0
318
330
. get ( & choice)
@@ -396,11 +408,13 @@ pub struct Proposals {
396
408
/// Limit output entries
397
409
#[ structopt( short, long) ]
398
410
pub limit : Option < usize > ,
411
+ #[ structopt( default_value = "direct" , long) ]
412
+ pub voting_group : String ,
399
413
}
400
414
impl Proposals {
401
415
pub fn exec ( self , model : CliController ) -> Result < ( ) , IapyxCommandError > {
402
416
print_delim ( ) ;
403
- for ( id, proposal) in model. proposals ( ) ?. iter ( ) . enumerate ( ) {
417
+ for ( id, proposal) in model. proposals ( & self . voting_group ) ?. iter ( ) . enumerate ( ) {
404
418
if let Some ( limit) = self . limit {
405
419
if id >= limit {
406
420
break ;
@@ -414,10 +428,10 @@ impl Proposals {
414
428
"{}. {} [{}] {}" ,
415
429
( id + 1 ) ,
416
430
proposal. chain_proposal_id_as_str( ) ,
417
- proposal. proposal_title,
418
- proposal. proposal_summary
431
+ proposal. proposal . proposal_title,
432
+ proposal. proposal . proposal_summary
419
433
) ;
420
- println ! ( "{:#?}" , proposal. chain_vote_options. 0 ) ;
434
+ println ! ( "{:#?}" , proposal. proposal . chain_vote_options. 0 ) ;
421
435
}
422
436
}
423
437
print_delim ( ) ;
0 commit comments