Skip to content

Commit fb66c47

Browse files
committed
fix(subgraph): court and subcourt naming inconsistency
1 parent 2e3508f commit fb66c47

File tree

4 files changed

+69
-72
lines changed

4 files changed

+69
-72
lines changed

subgraph/schema.graphql

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ type Court @entity {
1818
jurorsForCourtJump: BigInt!
1919
timesPerPeriod: [BigInt!]!
2020
supportedDisputeKits: [DisputeKit!]!
21-
disputes: [Dispute!]! @derivedFrom(field: "subcourtID")
21+
disputes: [Dispute!]! @derivedFrom(field: "courtID")
2222
numberDisputes: BigInt!
23-
stakedJurors: [JurorTokensPerSubcourt!]! @derivedFrom(field: "subcourt")
23+
stakedJurors: [JurorTokensPerCourt!]! @derivedFrom(field: "court")
2424
numberStakedJurors: BigInt!
25-
tokens: [JurorTokensPerSubcourt!]! @derivedFrom(field: "subcourt")
25+
tokens: [JurorTokensPerCourt!]! @derivedFrom(field: "court")
2626
stake: BigInt!
2727
paidETH: BigInt!
2828
paidPNK: BigInt!
2929
}
3030

3131
type Juror @entity {
3232
id: ID! # Set to address
33-
tokens: [JurorTokensPerSubcourt!]! @derivedFrom(field: "juror")
33+
tokens: [JurorTokensPerCourt!]! @derivedFrom(field: "juror")
3434
totalStake: BigInt!
3535
shifts: [TokenAndETHShift!]! @derivedFrom(field: "juror")
3636
draws: [Draw!]! @derivedFrom(field: "juror")
@@ -45,10 +45,10 @@ type TokenAndETHShift @entity {
4545
ethAmount: BigInt!
4646
}
4747

48-
type JurorTokensPerSubcourt @entity {
48+
type JurorTokensPerCourt @entity {
4949
id: ID! # Set to `${juror.id}-${court.id}`
5050
juror: Juror!
51-
subcourt: Court!
51+
court: Court!
5252
staked: BigInt!
5353
locked: BigInt!
5454
}
@@ -100,7 +100,7 @@ type Draw @entity {
100100

101101
type Dispute @entity {
102102
id: ID!
103-
subcourtID: Court!
103+
courtID: Court!
104104
arbitrated: Bytes!
105105
period: Period!
106106
ruled: Boolean!

subgraph/src/KlerosCore.ts

Lines changed: 56 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import {
66
DisputeCreation,
77
DisputeKitCreated,
88
DisputeKitEnabled,
9-
SubcourtCreated,
10-
SubcourtModified,
9+
CourtCreated,
10+
CourtModified,
1111
Draw as DrawEvent,
1212
NewPeriod,
1313
StakeSet,
@@ -16,7 +16,7 @@ import {
1616
import {
1717
Juror,
1818
TokenAndETHShift,
19-
JurorTokensPerSubcourt,
19+
JurorTokensPerCourt,
2020
Round,
2121
Draw,
2222
Dispute,
@@ -39,38 +39,37 @@ function getPeriodName(index: i32): string {
3939
return periodArray.at(index) || "None";
4040
}
4141

42-
export function handleSubcourtCreated(event: SubcourtCreated): void {
43-
const subcourt = new Court(event.params._subcourtID.toString());
44-
subcourt.hiddenVotes = event.params._hiddenVotes;
45-
subcourt.parent = event.params._parent.toString();
46-
subcourt.minStake = event.params._minStake;
47-
subcourt.alpha = event.params._alpha;
48-
subcourt.feeForJuror = event.params._feeForJuror;
49-
subcourt.jurorsForCourtJump = event.params._jurorsForCourtJump;
50-
subcourt.timesPerPeriod = event.params._timesPerPeriod;
51-
subcourt.supportedDisputeKits =
52-
event.params._supportedDisputeKits.map<string>((disputeKitID: BigInt) =>
53-
disputeKitID.toString()
54-
);
55-
subcourt.numberDisputes = ZERO;
56-
subcourt.numberStakedJurors = ZERO;
57-
subcourt.stake = ZERO;
58-
subcourt.paidETH = ZERO;
59-
subcourt.paidPNK = ZERO;
60-
subcourt.save();
42+
export function handleCourtCreated(event: CourtCreated): void {
43+
const court = new Court(event.params._courtID.toString());
44+
court.hiddenVotes = event.params._hiddenVotes;
45+
court.parent = event.params._parent.toString();
46+
court.minStake = event.params._minStake;
47+
court.alpha = event.params._alpha;
48+
court.feeForJuror = event.params._feeForJuror;
49+
court.jurorsForCourtJump = event.params._jurorsForCourtJump;
50+
court.timesPerPeriod = event.params._timesPerPeriod;
51+
court.supportedDisputeKits = event.params._supportedDisputeKits.map<string>(
52+
(disputeKitID: BigInt) => disputeKitID.toString()
53+
);
54+
court.numberDisputes = ZERO;
55+
court.numberStakedJurors = ZERO;
56+
court.stake = ZERO;
57+
court.paidETH = ZERO;
58+
court.paidPNK = ZERO;
59+
court.save();
6160
}
6261

63-
export function handleSubcourtModified(event: SubcourtModified): void {
64-
const court = Court.load(event.params._subcourtID.toString());
62+
export function handleCourtModified(event: CourtModified): void {
63+
const court = Court.load(event.params._courtID.toString());
6564
if (court) {
6665
const contract = KlerosCore.bind(event.address);
67-
const courtContractState = contract.courts(event.params._subcourtID);
66+
const courtContractState = contract.courts(event.params._courtID);
6867
court.hiddenVotes = courtContractState.value1;
6968
court.minStake = courtContractState.value2;
7069
court.alpha = courtContractState.value3;
7170
court.feeForJuror = courtContractState.value4;
7271
court.jurorsForCourtJump = courtContractState.value5;
73-
court.timesPerPeriod = contract.getTimesPerPeriod(event.params._subcourtID);
72+
court.timesPerPeriod = contract.getTimesPerPeriod(event.params._courtID);
7473
court.save();
7574
}
7675
}
@@ -88,7 +87,7 @@ export function handleDisputeKitCreated(event: DisputeKitCreated): void {
8887
}
8988

9089
export function handleDisputeKitEnabled(event: DisputeKitEnabled): void {
91-
const court = Court.load(event.params._subcourtID.toString());
90+
const court = Court.load(event.params._courtID.toString());
9291
if (court) {
9392
const isEnable = event.params._enable;
9493
const disputeKitID = event.params._disputeKitID.toString();
@@ -123,12 +122,12 @@ export function handleAppealDecision(event: AppealDecision): void {
123122
disputeID,
124123
BigInt.fromI64(newRoundIndex)
125124
);
126-
const subcourtID = dispute.subcourtID;
127-
const subcourtStorage = contract.courts(BigInt.fromString(subcourtID));
125+
const courtID = dispute.courtID;
126+
const courtStorage = contract.courts(BigInt.fromString(courtID));
128127
round.dispute = disputeID.toString();
129128
round.tokensAtStakePerJuror = roundInfo.value0;
130129
round.totalFeesForJurors = roundInfo.value1;
131-
round.nbVotes = roundInfo.value1.div(subcourtStorage.value4);
130+
round.nbVotes = roundInfo.value1.div(courtStorage.value4);
132131
round.totalVoted = BigInt.fromI32(0);
133132
round.repartitions = roundInfo.value2;
134133
round.penalties = roundInfo.value3;
@@ -144,10 +143,10 @@ export function handleDisputeCreation(event: DisputeCreation): void {
144143
const disputeID = event.params._disputeID;
145144
const dispute = new Dispute(disputeID.toString());
146145
const disputeStorage = contract.disputes(disputeID);
147-
const subcourtID = disputeStorage.value0;
148-
const subcourt = Court.load(subcourtID.toString());
146+
const courtID = disputeStorage.value0;
147+
const court = Court.load(courtID.toString());
149148
dispute.arbitrated = event.params._arbitrable;
150-
dispute.subcourtID = subcourtID.toString();
149+
dispute.courtID = courtID.toString();
151150
dispute.period = "Evidence";
152151
dispute.ruled = false;
153152
dispute.lastPeriodChange = disputeStorage.value4;
@@ -157,13 +156,13 @@ export function handleDisputeCreation(event: DisputeCreation): void {
157156
round.dispute = disputeID.toString();
158157
round.tokensAtStakePerJuror = roundInfo.value0;
159158
round.totalFeesForJurors = roundInfo.value1;
160-
round.nbVotes = subcourt ? roundInfo.value1.div(subcourt.feeForJuror) : ZERO;
159+
round.nbVotes = court ? roundInfo.value1.div(court.feeForJuror) : ZERO;
161160
round.totalVoted = BigInt.fromI32(0);
162161
round.repartitions = roundInfo.value2;
163162
round.penalties = roundInfo.value3;
164163
round.disputeKitID = roundInfo.value5.toString();
165-
if (subcourt) {
166-
subcourt.numberDisputes = subcourt.numberDisputes.plus(BigInt.fromI32(1));
164+
if (court) {
165+
court.numberDisputes = court.numberDisputes.plus(BigInt.fromI32(1));
167166
}
168167
dispute.save();
169168
round.save();
@@ -181,19 +180,17 @@ export function handleNewPeriod(event: NewPeriod): void {
181180

182181
function updateJurorStake(
183182
jurorAddress: string,
184-
subcourtID: string,
183+
courtID: string,
185184
contract: KlerosCore,
186185
timestamp: BigInt
187186
): void {
188187
const juror = Juror.load(jurorAddress);
189-
const subcourt = Court.load(subcourtID);
190-
const jurorTokens = JurorTokensPerSubcourt.load(
191-
`${jurorAddress}-${subcourtID}`
192-
);
193-
if (juror && subcourt && jurorTokens) {
188+
const court = Court.load(courtID);
189+
const jurorTokens = JurorTokensPerCourt.load(`${jurorAddress}-${courtID}`);
190+
if (juror && court && jurorTokens) {
194191
const jurorBalance = contract.getJurorBalance(
195192
Address.fromString(jurorAddress),
196-
BigInt.fromString(subcourtID)
193+
BigInt.fromString(courtID)
197194
);
198195
const previousStake = jurorTokens.staked;
199196
jurorTokens.staked = jurorBalance.value0;
@@ -202,7 +199,7 @@ function updateJurorStake(
202199
const stakeDelta = jurorTokens.staked.minus(previousStake);
203200
const previousTotalStake = juror.totalStake;
204201
juror.totalStake = juror.totalStake.plus(stakeDelta);
205-
subcourt.stake = subcourt.stake.plus(stakeDelta);
202+
court.stake = court.stake.plus(stakeDelta);
206203
let activeJurorsDelta: BigInt;
207204
let numberStakedJurorsDelta: BigInt;
208205
if (previousTotalStake.equals(ZERO)) {
@@ -215,12 +212,12 @@ function updateJurorStake(
215212
activeJurorsDelta = ZERO;
216213
numberStakedJurorsDelta = ZERO;
217214
}
218-
subcourt.numberStakedJurors = subcourt.numberStakedJurors.plus(
215+
court.numberStakedJurors = court.numberStakedJurors.plus(
219216
numberStakedJurorsDelta
220217
);
221218
updateActiveJurors(activeJurorsDelta, timestamp);
222219
juror.save();
223-
subcourt.save();
220+
court.save();
224221
}
225222
}
226223

@@ -241,7 +238,7 @@ export function handleDraw(event: DrawEvent): void {
241238
const contract = KlerosCore.bind(event.address);
242239
updateJurorStake(
243240
drawnAddress.toHexString(),
244-
dispute.subcourtID.toString(),
241+
dispute.courtID.toString(),
245242
contract,
246243
event.block.timestamp
247244
);
@@ -256,22 +253,22 @@ export function handleStakeSet(event: StakeSet): void {
256253
updateActiveJurors(BigInt.fromI32(1), event.block.timestamp);
257254
}
258255
juror.save();
259-
const subcourtID = event.params._subcourtID;
260-
const jurorTokensID = `${jurorAddress}-${subcourtID.toString()}`;
261-
let jurorTokens = JurorTokensPerSubcourt.load(jurorTokensID);
256+
const courtID = event.params._courtID;
257+
const jurorTokensID = `${jurorAddress}-${courtID.toString()}`;
258+
let jurorTokens = JurorTokensPerCourt.load(jurorTokensID);
262259
let previousStake: BigInt;
263260
if (!jurorTokens) {
264-
jurorTokens = new JurorTokensPerSubcourt(jurorTokensID);
261+
jurorTokens = new JurorTokensPerCourt(jurorTokensID);
265262
jurorTokens.juror = jurorAddress;
266-
jurorTokens.subcourt = subcourtID.toString();
263+
jurorTokens.court = courtID.toString();
267264
jurorTokens.staked = ZERO;
268265
jurorTokens.locked = ZERO;
269266
jurorTokens.save();
270267
previousStake = ZERO;
271268
} else previousStake = jurorTokens.staked;
272269
updateJurorStake(
273270
jurorAddress,
274-
subcourtID.toString(),
271+
courtID.toString(),
275272
KlerosCore.bind(event.address),
276273
event.block.timestamp
277274
);
@@ -297,17 +294,17 @@ export function handleTokenAndETHShift(event: TokenAndETHShiftEvent): void {
297294
shift.save();
298295
const dispute = Dispute.load(disputeID.toString());
299296
if (dispute) {
300-
const subcourt = Court.load(dispute.subcourtID.toString());
301-
if (subcourt) {
297+
const court = Court.load(dispute.courtID.toString());
298+
if (court) {
302299
updateJurorStake(
303300
jurorAddress,
304-
subcourt.id,
301+
court.id,
305302
KlerosCore.bind(event.address),
306303
event.block.timestamp
307304
);
308-
subcourt.paidETH = subcourt.paidETH.plus(ethAmount);
309-
subcourt.paidPNK = subcourt.paidETH.plus(tokenAmount);
310-
subcourt.save();
305+
court.paidETH = court.paidETH.plus(ethAmount);
306+
court.paidPNK = court.paidETH.plus(tokenAmount);
307+
court.save();
311308
}
312309
}
313310
}

subgraph/src/PolicyRegistry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { PolicyUpdate } from "../generated/PolicyRegistry/PolicyRegistry";
22
import { Court } from "../generated/schema";
33

44
export function handlePolicyUpdate(event: PolicyUpdate): void {
5-
const courtID = event.params._subcourtID.toString();
5+
const courtID = event.params._courtID.toString();
66
const court = Court.load(courtID);
77
if (court) {
88
court.policy = event.params._policy;

subgraph/subgraph.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ dataSources:
1717
- Court
1818
- Juror
1919
- TokenAndETHShift
20-
- JurorTokensPerSubcourt
20+
- JurorTokensPerCourt
2121
- Round
2222
- Draw
2323
- Dispute
@@ -39,10 +39,10 @@ dataSources:
3939
handler: handleDraw
4040
- event: NewPeriod(indexed uint256,uint8)
4141
handler: handleNewPeriod
42-
- event: SubcourtCreated(indexed uint256,indexed uint96,bool,uint256,uint256,uint256,uint256,uint256[4],uint256,uint256[])
43-
handler: handleSubcourtCreated
44-
- event: SubcourtModified(indexed uint96,string)
45-
handler: handleSubcourtModified
42+
- event: CourtCreated(indexed uint256,indexed uint96,bool,uint256,uint256,uint256,uint256,uint256[4],uint256,uint256[])
43+
handler: handleCourtCreated
44+
- event: CourtModified(indexed uint96,string)
45+
handler: handleCourtModified
4646
- event: DisputeKitCreated(indexed uint256,indexed address,indexed uint256)
4747
handler: handleDisputeKitCreated
4848
- event: DisputeKitEnabled(indexed uint96,indexed uint256,indexed bool)

0 commit comments

Comments
 (0)