@@ -25,15 +25,15 @@ class CurrentRulingInfo {
2525 tied : boolean ;
2626}
2727
28- export function updateCountsAndGetCurrentRuling ( id : string , choice : BigInt ) : CurrentRulingInfo {
28+ export function updateCountsAndGetCurrentRuling ( id : string , choice : BigInt , choiceCount : BigInt ) : CurrentRulingInfo {
2929 const round = ClassicRound . load ( id ) ;
3030 if ( ! round ) return { ruling : ZERO , tied : false } ;
3131 const choiceNum = choice . toI32 ( ) ;
32- const updatedCount = round . counts [ choiceNum ] . plus ( ONE ) ;
32+ const delta = choiceCount . minus ( round . counts [ choiceNum ] ) ;
3333 let newCounts : BigInt [ ] = [ ] ;
3434 for ( let i = 0 ; i < round . counts . length ; i ++ ) {
3535 if ( BigInt . fromI32 ( i ) . equals ( choice ) ) {
36- newCounts . push ( round . counts [ i ] . plus ( ONE ) ) ;
36+ newCounts . push ( choiceCount ) ;
3737 } else {
3838 newCounts . push ( round . counts [ i ] ) ;
3939 }
@@ -43,14 +43,14 @@ export function updateCountsAndGetCurrentRuling(id: string, choice: BigInt): Cur
4343 if ( choice . equals ( round . winningChoice ) ) {
4444 if ( round . tied ) round . tied = false ;
4545 } else {
46- if ( updatedCount . equals ( currentWinningCount ) ) {
46+ if ( choiceCount . equals ( currentWinningCount ) ) {
4747 if ( ! round . tied ) round . tied = true ;
48- } else if ( updatedCount . gt ( currentWinningCount ) ) {
48+ } else if ( choiceCount . gt ( currentWinningCount ) ) {
4949 round . winningChoice = choice ;
5050 round . tied = false ;
5151 }
5252 }
53- round . totalVoted = round . totalVoted . plus ( ONE ) ;
53+ round . totalVoted = round . totalVoted . plus ( delta ) ;
5454 round . save ( ) ;
5555 return { ruling : round . winningChoice , tied : round . tied } ;
5656}
0 commit comments