Skip to content

Commit 316f1f8

Browse files
alcercujaybuidl
authored andcommitted
feat(subgraph): use numberOfChoices to model the length of arrays
1 parent dd8f927 commit 316f1f8

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

subgraph/src/DisputeKitClassic.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ export const DISPUTEKIT_ID = "1";
2929
export function handleDisputeCreation(event: DisputeCreation): void {
3030
const disputeID = event.params._coreDisputeID.toString();
3131
createClassicDisputeFromEvent(event);
32-
createClassicRound(disputeID, ZERO);
32+
const numberOfChoices = event.params._numberOfChoices;
33+
createClassicRound(disputeID, numberOfChoices, ZERO);
3334
}
3435

3536
export function handleEvidenceEvent(event: EvidenceEvent): void {
@@ -88,7 +89,8 @@ export function handleChoiceFunded(event: ChoiceFunded): void {
8889
);
8990
if (!localDispute) return;
9091
const newRoundIndex = localDispute.currentLocalRoundIndex.plus(ONE);
91-
createClassicRound(coreDisputeID, newRoundIndex);
92+
const numberOfChoices = localDispute.numberOfChoices;
93+
createClassicRound(coreDisputeID, numberOfChoices, newRoundIndex);
9294
}
9395

9496
localRound.save();

subgraph/src/entities/ClassicRound.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
import { BigInt } from "@graphprotocol/graph-ts";
22
import { Contribution } from "../../generated/DisputeKitClassic/DisputeKitClassic";
33
import { ClassicRound } from "../../generated/schema";
4-
import { ZERO } from "../utils";
4+
import { ONE, ZERO } from "../utils";
55

66
export function createClassicRound(
77
disputeID: string,
8+
numberOfChoices: BigInt,
89
roundIndex: BigInt
910
): void {
11+
const choicesLength = numberOfChoices.plus(ONE);
1012
const localDisputeID = `1-${disputeID}`;
1113
const id = `${localDisputeID}-${roundIndex.toString()}`;
1214
const classicRound = new ClassicRound(id);
1315
classicRound.localDispute = localDisputeID;
1416
classicRound.votes = [];
1517
classicRound.winningChoice = ZERO;
16-
classicRound.counts = [];
18+
classicRound.counts = new Array<BigInt>(choicesLength.toI32()).fill(ZERO);
1719
classicRound.tied = true;
1820
classicRound.totalVoted = ZERO;
1921
classicRound.totalCommited = ZERO;
20-
classicRound.paidFees = [];
22+
classicRound.paidFees = new Array<BigInt>(choicesLength.toI32()).fill(ZERO);
2123
classicRound.feeRewards = ZERO;
2224
classicRound.fundedChoices = [];
2325
classicRound.save();

0 commit comments

Comments
 (0)