File tree 2 files changed +24
-3
lines changed
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";
20
20
import {
21
21
createClassicRound ,
22
22
updateChoiceFundingFromContributionEvent ,
23
+ updateCounts ,
23
24
} from "./entities/ClassicRound" ;
24
25
import { createClassicVote } from "./entities/ClassicVote" ;
25
26
import { ONE , ZERO } from "./utils" ;
@@ -53,9 +54,9 @@ export function handleJustificationEvent(event: JustificationEvent): void {
53
54
const classicDisputeID = `${ DISPUTEKIT_ID } -${ coreDisputeID } ` ;
54
55
const classicDispute = ClassicDispute . load ( classicDisputeID ) ;
55
56
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 ) ;
59
60
createClassicVote ( currentLocalRoundID , event ) ;
60
61
}
61
62
Original file line number Diff line number Diff line change @@ -25,6 +25,26 @@ export function createClassicRound(
25
25
classicRound . save ( ) ;
26
26
}
27
27
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
+
28
48
export function updateChoiceFundingFromContributionEvent (
29
49
event : Contribution
30
50
) : void {
You can’t perform that action at this time.
0 commit comments