1- use catalyst_toolbox:: rewards:: voters:: { calc_voter_rewards, Rewards , Threshold , VoteCount } ;
1+ use catalyst_toolbox:: rewards:: voters:: calc_voter_rewards;
2+ use catalyst_toolbox:: rewards:: { Rewards , Threshold } ;
23use catalyst_toolbox:: utils:: assert_are_close;
3- use jormungandr_lib:: {
4- crypto:: { account:: Identifier , hash:: Hash } ,
5- interfaces:: AccountVotes ,
6- } ;
7- use snapshot_lib:: { registration:: MainnetRewardAddress , SnapshotInfo } ;
8- use vit_servicing_station_lib:: db:: models:: proposals:: FullProposalInfo ;
9-
10- use color_eyre:: { eyre:: eyre, Report } ;
4+ use color_eyre:: Report ;
115use jcli_lib:: jcli_lib:: block:: Common ;
6+ use jormungandr_lib:: { crypto:: account:: Identifier , interfaces:: AccountVotes } ;
7+ use snapshot_lib:: { registration:: MainnetRewardAddress , SnapshotInfo } ;
128use structopt:: StructOpt ;
9+ use vit_servicing_station_lib:: db:: models:: proposals:: FullProposalInfo ;
1310
1411use std:: collections:: { BTreeMap , HashMap } ;
1512use std:: path:: PathBuf ;
@@ -78,43 +75,16 @@ impl VotersRewards {
7875 proposals,
7976 } = self ;
8077
81- let proposals_per_voteplan = serde_json:: from_reader :: < _ , Vec < FullProposalInfo > > (
78+ let proposals = serde_json:: from_reader :: < _ , Vec < FullProposalInfo > > (
8279 jcli_lib:: utils:: io:: open_file_read ( & Some ( proposals) ) ?,
83- ) ?
84- . into_iter ( )
85- . fold ( <HashMap < _ , Vec < _ > > >:: new ( ) , |mut acc, prop| {
86- let entry = acc
87- . entry ( prop. voteplan . chain_voteplan_id . clone ( ) )
88- . or_default ( ) ;
89- entry. push ( prop) ;
90- entry. sort_by_key ( |p| p. voteplan . chain_proposal_index ) ;
91- acc
92- } ) ;
93- let vote_count = serde_json:: from_reader :: < _ , HashMap < Identifier , Vec < AccountVotes > > > (
94- jcli_lib:: utils:: io:: open_file_read ( & Some ( votes_count_path) ) ?,
95- ) ?
96- . into_iter ( )
97- . try_fold ( VoteCount :: new ( ) , |mut acc, ( account, votes) | {
98- for vote in & votes {
99- let voteplan = vote. vote_plan_id ;
100- let props = proposals_per_voteplan
101- . get ( & voteplan. to_string ( ) )
102- . iter ( )
103- . flat_map ( |p| p. iter ( ) )
104- . enumerate ( )
105- . filter ( |( i, _p) | vote. votes . contains ( & ( * i as u8 ) ) )
106- . map ( |( _, p) | {
107- Ok :: < _ , Report > ( Hash :: from (
108- <[ u8 ; 32 ] >:: try_from ( p. proposal . chain_proposal_id . clone ( ) ) . map_err (
109- |v| eyre ! ( "Invalid proposal hash length {}, expected 32" , v. len( ) ) ,
110- ) ?,
111- ) )
112- } )
113- . collect :: < Result < Vec < _ > , _ > > ( ) ?;
114- acc. entry ( account. clone ( ) ) . or_default ( ) . extend ( props) ;
115- }
116- Ok :: < _ , Report > ( acc)
117- } ) ?;
80+ ) ?;
81+
82+ let vote_count = super :: extract_individual_votes (
83+ proposals. clone ( ) ,
84+ serde_json:: from_reader :: < _ , HashMap < Identifier , Vec < AccountVotes > > > (
85+ jcli_lib:: utils:: io:: open_file_read ( & Some ( votes_count_path) ) ?,
86+ ) ?,
87+ ) ?;
11888
11989 let snapshot: Vec < SnapshotInfo > = serde_json:: from_reader (
12090 jcli_lib:: utils:: io:: open_file_read ( & Some ( snapshot_info_path) ) ?,
@@ -130,14 +100,7 @@ impl VotersRewards {
130100 let results = calc_voter_rewards (
131101 vote_count,
132102 snapshot,
133- Threshold :: new (
134- vote_threshold,
135- additional_thresholds,
136- proposals_per_voteplan
137- . into_iter ( )
138- . flat_map ( |( _k, v) | v. into_iter ( ) )
139- . collect ( ) ,
140- ) ?,
103+ Threshold :: new ( vote_threshold, additional_thresholds, proposals) ?,
141104 Rewards :: from ( total_rewards) ,
142105 ) ?;
143106
0 commit comments