Skip to content

Commit d405d38

Browse files
feat(subgraph): handle court jump and refactor
1 parent fb14bf2 commit d405d38

File tree

6 files changed

+18
-51
lines changed

6 files changed

+18
-51
lines changed

subgraph/schema.graphql

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,6 @@ type Court @entity {
119119
id: ID!
120120
policy: String
121121
name: String
122-
description: String
123-
summary: String
124-
requiredSkills: String
125122
parent: Court
126123
hiddenVotes: Boolean!
127124
children: [Court!]! @derivedFrom(field: "parent")
@@ -156,14 +153,14 @@ type Dispute @entity {
156153
overridden: Boolean!
157154
periodDeadline: BigInt!
158155
periodNotificationIndex: BigInt!
159-
lastPeriodChangeTs: BigInt!
156+
lastPeriodChange: BigInt!
160157
lastPeriodChangeBlockNumber: BigInt!
161158
rounds: [Round!]! @derivedFrom(field: "dispute")
162159
currentRound: Round!
163160
currentRoundIndex: BigInt!
164161
jurors: [User!]! @derivedFrom(field: "disputes")
165162
shifts: [TokenAndETHShift!]! @derivedFrom(field: "dispute")
166-
disputeKitDispute: DisputeKitDispute @derivedFrom(field: "coreDispute")
163+
disputeKitDispute: [DisputeKitDispute!]! @derivedFrom(field: "coreDispute")
167164
}
168165

169166
type PeriodIndexCounter @entity {
@@ -241,7 +238,6 @@ type ClassicDispute implements DisputeKitDispute @entity {
241238
currentLocalRoundIndex: BigInt!
242239

243240
numberOfChoices: BigInt!
244-
jumped: Boolean!
245241
extraData: Bytes!
246242
}
247243

subgraph/src/KlerosCore.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
NewPeriod,
1111
StakeSet,
1212
TokenAndETHShift as TokenAndETHShiftEvent,
13+
CourtJump,
1314
Ruling,
1415
StakeDelayed,
1516
AcceptedFeeToken,
@@ -25,10 +26,11 @@ import { updateJurorDelayedStake, updateJurorStake } from "./entities/JurorToken
2526
import { createDrawFromEvent } from "./entities/Draw";
2627
import { updateTokenAndEthShiftFromEvent } from "./entities/TokenAndEthShift";
2728
import { updateArbitrableCases } from "./entities/Arbitrable";
28-
import { Court, Dispute, User, PeriodIndexCounter } from "../generated/schema";
29+
import { Court, Dispute, User } from "../generated/schema";
2930
import { BigInt } from "@graphprotocol/graph-ts";
3031
import { updatePenalty } from "./entities/Penalty";
3132
import { ensureFeeToken } from "./entities/FeeToken";
33+
import { getAndIncrementCounter } from "./entities/PeriodIndexCounter";
3234

3335
function getPeriodName(index: i32): string {
3436
const periodArray = ["evidence", "commit", "vote", "appeal", "execution"];
@@ -126,21 +128,11 @@ export function handleNewPeriod(event: NewPeriod): void {
126128
}
127129

128130
dispute.period = newPeriod;
129-
dispute.lastPeriodChangeTs = event.block.timestamp;
130-
dispute.lastPeriodChangeBlockNumber = event.block.number;
131-
let counter = PeriodIndexCounter.load(newPeriod);
132-
if (!counter) {
133-
counter = new PeriodIndexCounter(newPeriod);
134-
counter.counter = BigInt.fromI32(0);
135-
}
136-
dispute.periodNotificationIndex = counter.counter;
137-
counter.counter = counter.counter.plus(ONE);
138-
counter.save();
131+
dispute.lastPeriodChange = event.block.timestamp;
139132
dispute.lastPeriodChangeBlockNumber = event.block.number;
133+
dispute.periodNotificationIndex = getAndIncrementCounter(newPeriod);
140134
if (newPeriod !== "execution") {
141-
const contract = KlerosCore.bind(event.address);
142-
const courtContractState = contract.getTimesPerPeriod(BigInt.fromString(dispute.court));
143-
dispute.periodDeadline = event.block.timestamp.plus(courtContractState[event.params._period]);
135+
dispute.periodDeadline = event.block.timestamp.plus(court.timesPerPeriod[event.params._period]);
144136
} else {
145137
dispute.periodDeadline = BigInt.fromU64(U64.MAX_VALUE);
146138
}
@@ -175,6 +167,13 @@ export function handleAppealDecision(event: AppealDecision): void {
175167
createRoundFromRoundInfo(disputeID, newRoundIndex, roundInfo);
176168
}
177169

170+
export function handleCourtJump(event: CourtJump): void {
171+
const dispute = Dispute.load(event.params._disputeID.toString());
172+
if (!dispute) return;
173+
dispute.court = event.params._toCourtID.toString();
174+
dispute.save();
175+
}
176+
178177
export function handleDraw(event: DrawEvent): void {
179178
createDrawFromEvent(event);
180179
const disputeID = event.params._disputeID.toString();

subgraph/src/PolicyRegistry.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { PolicyUpdate } from "../generated/PolicyRegistry/PolicyRegistry";
22
import { Court } from "../generated/schema";
3-
import { ipfs, json, Bytes, TypedMap, JSONValue } from "@graphprotocol/graph-ts";
43

54
export function handlePolicyUpdate(event: PolicyUpdate): void {
65
const courtID = event.params._courtID.toString();
@@ -9,31 +8,5 @@ export function handlePolicyUpdate(event: PolicyUpdate): void {
98
court.policy = event.params._policy;
109
court.name = event.params._courtName;
1110
court.save();
12-
13-
const jsonObj = getJsonObj(event.params._policy);
14-
if (!jsonObj) return;
15-
16-
court.name = tryGetValue(jsonObj, "name");
17-
court.description = tryGetValue(jsonObj, "description");
18-
court.requiredSkills = tryGetValue(jsonObj, "requiredSkills");
19-
court.save();
2011
}
2112
}
22-
23-
function tryGetValue(jsonObj: TypedMap<string, JSONValue>, key: string): string | null {
24-
const value = jsonObj.get(key);
25-
return value ? value.toString() : null;
26-
}
27-
28-
function getJsonObj(CID: string): TypedMap<string, JSONValue> | null {
29-
const jsonStr = ipfs.cat(CID);
30-
if (!jsonStr) return null;
31-
32-
const jsonObjValueAndSuccess = json.try_fromBytes(jsonStr as Bytes);
33-
if (!jsonObjValueAndSuccess.isOk) return null;
34-
35-
const jsonObj = jsonObjValueAndSuccess.value.toObject();
36-
if (!jsonObj) return null;
37-
38-
return jsonObj;
39-
}

subgraph/src/entities/ClassicDispute.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export function createClassicDisputeFromEvent(event: DisputeCreation): void {
88
classicDispute.coreDispute = coreDisputeID;
99
classicDispute.currentLocalRoundIndex = ZERO;
1010
classicDispute.numberOfChoices = event.params._numberOfChoices;
11-
classicDispute.jumped = false;
1211
classicDispute.extraData = event.params._extraData;
1312
classicDispute.save();
1413
}

subgraph/src/entities/Dispute.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function createDisputeFromEvent(event: DisputeCreation): void {
1616
dispute.currentRuling = ZERO;
1717
dispute.tied = true;
1818
dispute.overridden = false;
19-
dispute.lastPeriodChangeTs = event.block.timestamp;
19+
dispute.lastPeriodChange = event.block.timestamp;
2020
dispute.lastPeriodChangeBlockNumber = event.block.number;
2121
dispute.periodNotificationIndex = getAndIncrementCounter(dispute.period);
2222
const court = Court.load(courtID);

subgraph/subgraph.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
specVersion: 0.0.4
22
schema:
33
file: ./schema.graphql
4-
features:
5-
- ipfsOnEthereumContracts
64
dataSources:
75
- kind: ethereum
86
name: KlerosCore
@@ -58,6 +56,8 @@ dataSources:
5856
handler: handleRuling
5957
- event: AcceptedFeeToken(indexed address,indexed bool)
6058
handler: handleAcceptedFeeToken
59+
- event: CourtJump(indexed uint256,indexed uint256,indexed uint96,uint96)
60+
handler: handleCourtJump
6161
file: ./src/KlerosCore.ts
6262
- kind: ethereum
6363
name: PolicyRegistry

0 commit comments

Comments
 (0)