Skip to content

Commit 05dcdb0

Browse files
committed
fix: create new classic dispute entity correctly with correct round index
1 parent 317aed6 commit 05dcdb0

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

subgraph/core/src/DisputeKitClassic.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,7 @@ import {
99
CommitCast,
1010
} from "../generated/DisputeKitClassic/DisputeKitClassic";
1111
import { KlerosCore } from "../generated/KlerosCore/KlerosCore";
12-
import {
13-
ClassicDispute,
14-
ClassicJustification,
15-
ClassicRound,
16-
ClassicVote,
17-
Dispute,
18-
DisputeKit,
19-
Round,
20-
} from "../generated/schema";
12+
import { ClassicDispute, ClassicJustification, ClassicRound, ClassicVote, Dispute, Round } from "../generated/schema";
2113
import { ensureClassicContributionFromEvent } from "./entities/ClassicContribution";
2214
import { createClassicDisputeFromEvent } from "./entities/ClassicDispute";
2315
import {
@@ -27,14 +19,19 @@ import {
2719
updateCountsAndGetCurrentRuling,
2820
} from "./entities/ClassicRound";
2921
import { ensureClassicVote } from "./entities/ClassicVote";
30-
import { ONE, ZERO, extractDisputeKitIDFromExtraData } from "./utils";
22+
import { ONE, extractDisputeKitIDFromExtraData } from "./utils";
3123

3224
export function handleDisputeCreation(event: DisputeCreation): void {
3325
const disputeID = event.params._coreDisputeID.toString();
3426
const disputeKitID = extractDisputeKitIDFromExtraData(event.params._extraData);
35-
createClassicDisputeFromEvent(event, disputeKitID);
36-
const numberOfChoices = event.params._numberOfChoices;
37-
createClassicRound(disputeID, numberOfChoices, ZERO, disputeKitID);
27+
28+
const disputeKitClassic = DisputeKitClassic.bind(event.address);
29+
const klerosCore = KlerosCore.bind(disputeKitClassic.core());
30+
const totalRounds = klerosCore.getNumberOfRounds(event.params._coreDisputeID);
31+
const newRoundIndex = totalRounds.minus(ONE);
32+
33+
createClassicDisputeFromEvent(event, disputeKitID, newRoundIndex);
34+
createClassicRound(disputeID, event.params._numberOfChoices, newRoundIndex, disputeKitID);
3835
}
3936

4037
export function handleCommitCast(event: CommitCast): void {
@@ -156,16 +153,23 @@ export function handleChoiceFunded(event: ChoiceFunded): void {
156153
const numberOfRounds = klerosCore.getNumberOfRounds(BigInt.fromString(coreDisputeID));
157154
const roundInfo = klerosCore.getRoundInfo(BigInt.fromString(coreDisputeID), numberOfRounds.minus(ONE));
158155
const appealCost = roundInfo.totalFeesForJurors;
156+
const currentDisputeKitID = roundInfo.disputeKitID;
159157

160158
localRound.feeRewards = localRound.feeRewards.minus(appealCost);
161159

160+
const newRoundInfo = klerosCore.getRoundInfo(BigInt.fromString(coreDisputeID), numberOfRounds);
161+
const newDisputeKitID = newRoundInfo.disputeKitID;
162+
162163
const localDispute = ClassicDispute.load(`${disputeKitID}-${coreDisputeID}`);
163164
if (!localDispute) return;
164-
const newRoundIndex = localDispute.currentLocalRoundIndex.plus(ONE);
165-
const numberOfChoices = localDispute.numberOfChoices;
166-
localDispute.currentLocalRoundIndex = newRoundIndex;
167-
localDispute.save();
168-
createClassicRound(coreDisputeID, numberOfChoices, newRoundIndex, disputeKitID);
165+
166+
if (currentDisputeKitID === newDisputeKitID) {
167+
const newRoundIndex = localDispute.currentLocalRoundIndex.plus(ONE);
168+
const numberOfChoices = localDispute.numberOfChoices;
169+
localDispute.currentLocalRoundIndex = newRoundIndex;
170+
localDispute.save();
171+
createClassicRound(coreDisputeID, numberOfChoices, newRoundIndex, disputeKitID);
172+
}
169173
}
170174

171175
localRound.save();

subgraph/core/src/entities/ClassicDispute.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import { Bytes } from "@graphprotocol/graph-ts";
1+
import { BigInt } from "@graphprotocol/graph-ts";
22
import { DisputeCreation } from "../../generated/DisputeKitClassic/DisputeKitClassic";
33
import { ClassicDispute } from "../../generated/schema";
4-
import { ZERO } from "../utils";
54

6-
export function createClassicDisputeFromEvent(event: DisputeCreation, disputeKitID: string): void {
5+
export function createClassicDisputeFromEvent(event: DisputeCreation, disputeKitID: string, roundIndex: BigInt): void {
76
const coreDisputeID = event.params._coreDisputeID.toString();
87
const classicDispute = new ClassicDispute(`${disputeKitID}-${coreDisputeID}`);
98
classicDispute.coreDispute = coreDisputeID;
10-
classicDispute.currentLocalRoundIndex = ZERO;
9+
classicDispute.currentLocalRoundIndex = roundIndex;
1110
classicDispute.numberOfChoices = event.params._numberOfChoices;
1211
classicDispute.extraData = event.params._extraData;
1312
classicDispute.timestamp = event.block.timestamp;

0 commit comments

Comments
 (0)