Skip to content

Commit 76a1310

Browse files
authored
Merge pull request #1077 from kleros/feat(subgraph)/add-overridden-to-dispute
Feat(subgraph): add more ruling information to dispute entity
2 parents b287ce3 + ad6ad71 commit 76a1310

File tree

5 files changed

+39
-21
lines changed

5 files changed

+39
-21
lines changed

subgraph/schema.graphql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ type Dispute @entity {
138138
arbitrated: Arbitrable!
139139
period: Period!
140140
ruled: Boolean!
141+
currentRuling: BigInt!
142+
tied: Boolean!
143+
overridden: Boolean!
141144
lastPeriodChange: BigInt!
142145
rounds: [Round!]! @derivedFrom(field: "dispute")
143146
currentRound: Round!

subgraph/src/DisputeKitClassic.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ import {
99
Withdrawal,
1010
} from "../generated/DisputeKitClassic/DisputeKitClassic";
1111
import { KlerosCore } from "../generated/KlerosCore/KlerosCore";
12-
import { ClassicDispute, ClassicEvidence, ClassicRound } from "../generated/schema";
12+
import { ClassicDispute, ClassicEvidence, ClassicRound, Dispute } from "../generated/schema";
1313
import { ensureClassicContributionFromEvent } from "./entities/ClassicContribution";
1414
import { createClassicDisputeFromEvent } from "./entities/ClassicDispute";
1515
import { ensureClassicEvidenceGroup } from "./entities/ClassicEvidenceGroup";
16-
import { createClassicRound, updateChoiceFundingFromContributionEvent, updateCounts } from "./entities/ClassicRound";
16+
import {
17+
createClassicRound,
18+
updateChoiceFundingFromContributionEvent,
19+
updateCountsAndGetCurrentRuling,
20+
} from "./entities/ClassicRound";
1721
import { createClassicVote } from "./entities/ClassicVote";
1822
import { ensureUser } from "./entities/User";
1923
import { ONE, ZERO } from "./utils";
@@ -44,11 +48,15 @@ export function handleEvidenceEvent(event: EvidenceEvent): void {
4448

4549
export function handleJustificationEvent(event: JustificationEvent): void {
4650
const coreDisputeID = event.params._coreDisputeID.toString();
51+
const coreDispute = Dispute.load(coreDisputeID);
4752
const classicDisputeID = `${DISPUTEKIT_ID}-${coreDisputeID}`;
4853
const classicDispute = ClassicDispute.load(classicDisputeID);
49-
if (!classicDispute) return;
54+
if (!classicDispute || !coreDispute) return;
5055
const currentLocalRoundID = classicDispute.id + "-" + classicDispute.currentLocalRoundIndex.toString();
51-
updateCounts(currentLocalRoundID, event.params._choice);
56+
const currentRulingInfo = updateCountsAndGetCurrentRuling(currentLocalRoundID, event.params._choice);
57+
coreDispute.currentRuling = currentRulingInfo.ruling;
58+
coreDispute.tied = currentRulingInfo.tied;
59+
coreDispute.save();
5260
createClassicVote(currentLocalRoundID, event);
5361
}
5462

subgraph/src/KlerosCore.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { updateCases, updatePaidETH, updateRedistributedPNK, updateCasesRuled, u
2222
import { addUserActiveDispute, ensureUser } from "./entities/User";
2323
import { updateJurorDelayedStake, updateJurorStake } from "./entities/JurorTokensPerCourt";
2424
import { createDrawFromEvent } from "./entities/Draw";
25-
import { createTokenAndEthShiftFromEvent, updateTokenAndEthShiftFromEvent } from "./entities/TokenAndEthShift";
25+
import { updateTokenAndEthShiftFromEvent } from "./entities/TokenAndEthShift";
2626
import { updateArbitrableCases } from "./entities/Arbitrable";
2727
import { Court, Dispute } from "../generated/schema";
2828
import { BigInt } from "@graphprotocol/graph-ts";
@@ -82,14 +82,21 @@ export function handleDisputeCreation(event: DisputeCreation): void {
8282
}
8383

8484
export function handleNewPeriod(event: NewPeriod): void {
85-
const disputeID = event.params._disputeID.toString();
86-
const dispute = Dispute.load(disputeID);
85+
const disputeID = event.params._disputeID;
86+
const dispute = Dispute.load(disputeID.toString());
8787
if (!dispute) return;
8888
const newPeriod = getPeriodName(event.params._period);
8989
if (dispute.period === "vote") {
9090
updateCasesVoting(BigInt.fromI32(-1), event.block.timestamp);
9191
} else if (newPeriod === "vote") {
9292
updateCasesVoting(ONE, event.block.timestamp);
93+
} else if (newPeriod === "execution") {
94+
const contract = KlerosCore.bind(event.address);
95+
const currentRulingInfo = contract.currentRuling(disputeID);
96+
dispute.currentRuling = currentRulingInfo.getRuling();
97+
dispute.overridden = currentRulingInfo.getOverridden();
98+
dispute.tied = currentRulingInfo.getTied();
99+
dispute.save();
93100
}
94101
dispute.period = newPeriod;
95102
dispute.lastPeriodChange = event.block.timestamp;

subgraph/src/entities/ClassicRound.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@ import { Contribution } from "../../generated/DisputeKitClassic/DisputeKitClassi
33
import { ClassicRound } from "../../generated/schema";
44
import { ONE, ZERO } from "../utils";
55

6-
export function createClassicRound(
7-
disputeID: string,
8-
numberOfChoices: BigInt,
9-
roundIndex: BigInt
10-
): void {
6+
export function createClassicRound(disputeID: string, numberOfChoices: BigInt, roundIndex: BigInt): void {
117
const choicesLength = numberOfChoices.plus(ONE);
128
const localDisputeID = `1-${disputeID}`;
139
const id = `${localDisputeID}-${roundIndex.toString()}`;
@@ -24,9 +20,14 @@ export function createClassicRound(
2420
classicRound.save();
2521
}
2622

27-
export function updateCounts(id: string, choice: BigInt): void {
23+
class CurrentRulingInfo {
24+
ruling: BigInt;
25+
tied: boolean;
26+
}
27+
28+
export function updateCountsAndGetCurrentRuling(id: string, choice: BigInt): CurrentRulingInfo {
2829
const round = ClassicRound.load(id);
29-
if (!round) return;
30+
if (!round) return { ruling: ZERO, tied: false };
3031
const choiceNum = choice.toI32();
3132
const updatedCount = round.counts[choiceNum].plus(ONE);
3233
let newCounts: BigInt[] = [];
@@ -51,11 +52,10 @@ export function updateCounts(id: string, choice: BigInt): void {
5152
}
5253
round.totalVoted = round.totalVoted.plus(ONE);
5354
round.save();
55+
return { ruling: round.winningChoice, tied: round.tied };
5456
}
5557

56-
export function updateChoiceFundingFromContributionEvent(
57-
event: Contribution
58-
): void {
58+
export function updateChoiceFundingFromContributionEvent(event: Contribution): void {
5959
const disputeKitID = "1";
6060
const coreDisputeID = event.params._coreDisputeID.toString();
6161
const coreRoundIndex = event.params._coreRoundID.toString();

subgraph/src/entities/Dispute.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import {
2-
KlerosCore,
3-
DisputeCreation,
4-
} from "../../generated/KlerosCore/KlerosCore";
1+
import { KlerosCore, DisputeCreation } from "../../generated/KlerosCore/KlerosCore";
52
import { Dispute } from "../../generated/schema";
63
import { ZERO } from "../utils";
74

@@ -14,6 +11,9 @@ export function createDisputeFromEvent(event: DisputeCreation): void {
1411
dispute.arbitrated = event.params._arbitrable.toHexString();
1512
dispute.period = "evidence";
1613
dispute.ruled = false;
14+
dispute.currentRuling = ZERO;
15+
dispute.tied = true;
16+
dispute.overridden = false;
1717
dispute.lastPeriodChange = event.block.timestamp;
1818
dispute.currentRoundIndex = ZERO;
1919
const roundID = `${disputeID.toString()}-${ZERO.toString()}`;

0 commit comments

Comments
 (0)