File tree Expand file tree Collapse file tree 2 files changed +24
-3
lines changed
Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import { ensureClassicEvidenceGroup } from "./entities/ClassicEvidenceGroup";
2020import {
2121 createClassicRound ,
2222 updateChoiceFundingFromContributionEvent ,
23+ updateCounts ,
2324} from "./entities/ClassicRound" ;
2425import { createClassicVote } from "./entities/ClassicVote" ;
2526import { ONE , ZERO } from "./utils" ;
@@ -53,9 +54,9 @@ export function handleJustificationEvent(event: JustificationEvent): void {
5354 const classicDisputeID = `${ DISPUTEKIT_ID } -${ coreDisputeID } ` ;
5455 const classicDispute = ClassicDispute . load ( classicDisputeID ) ;
5556 if ( ! classicDispute ) return ;
56- const currentLocalRoundID = ` ${
57- classicDispute . id
58- } - ${ classicDispute . currentLocalRoundIndex . toString ( ) } ` ;
57+ const currentLocalRoundID =
58+ classicDispute . id + "-" + classicDispute . currentLocalRoundIndex . toString ( ) ;
59+ updateCounts ( currentLocalRoundID , event . params . _choice ) ;
5960 createClassicVote ( currentLocalRoundID , event ) ;
6061}
6162
Original file line number Diff line number Diff line change @@ -25,6 +25,26 @@ export function createClassicRound(
2525 classicRound . save ( ) ;
2626}
2727
28+ export function updateCounts ( id : string , choice : BigInt ) : void {
29+ const round = ClassicRound . load ( id ) ;
30+ if ( ! round ) return ;
31+ const choiceNum = choice . toI32 ( ) ;
32+ const updatedCount = round . counts [ choiceNum ] . plus ( ONE ) ;
33+ round . counts [ choiceNum ] = updatedCount ;
34+ const currentWinningCount = round . counts [ round . winningChoice . toI32 ( ) ] ;
35+ if ( choice . equals ( round . winningChoice ) ) {
36+ if ( round . tied ) round . tied = false ;
37+ } else {
38+ if ( updatedCount . equals ( currentWinningCount ) ) {
39+ if ( ! round . tied ) round . tied = true ;
40+ } else if ( updatedCount . gt ( currentWinningCount ) ) {
41+ round . winningChoice = choice ;
42+ round . tied = false ;
43+ }
44+ }
45+ round . save ( ) ;
46+ }
47+
2848export function updateChoiceFundingFromContributionEvent (
2949 event : Contribution
3050) : void {
You can’t perform that action at this time.
0 commit comments