Skip to content

Commit dd61932

Browse files
alcercujaybuidl
authored andcommitted
fix(subgraph): correctly update counts and winningchoice
1 parent a29a255 commit dd61932

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

subgraph/src/DisputeKitClassic.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { ensureClassicEvidenceGroup } from "./entities/ClassicEvidenceGroup";
2020
import {
2121
createClassicRound,
2222
updateChoiceFundingFromContributionEvent,
23+
updateCounts,
2324
} from "./entities/ClassicRound";
2425
import { createClassicVote } from "./entities/ClassicVote";
2526
import { 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

subgraph/src/entities/ClassicRound.ts

+20
Original file line numberDiff line numberDiff 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+
2848
export function updateChoiceFundingFromContributionEvent(
2949
event: Contribution
3050
): void {

0 commit comments

Comments
 (0)