Skip to content

Commit 64640b0

Browse files
authored
Merge pull request #20 from Corantin/fix-bad-dispute-state
Fix bad dispute state
2 parents 4c7316a + fb712e9 commit 64640b0

File tree

7 files changed

+34
-47
lines changed

7 files changed

+34
-47
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ package-lock.json
88
build
99
types
1010
subgraph.yaml
11-
deploy-output.txt
11+
deploy-output.txt

.vscode/settings.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"prettier.semi": false,
3+
"typescript.preferences.quoteStyle": "double"
4+
}

helpers/disputable.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
import { concat } from './bytes'
2-
import { Agreement } from '../types/templates/DisputeManager/Agreement'
3-
import { Disputable, Dispute } from '../types/schema'
1+
import { concat } from "./bytes"
2+
import { Agreement } from "../types/templates/DisputeManager/Agreement"
3+
import { Disputable, Dispute } from "../types/schema"
44
import {
55
crypto,
66
Bytes,
77
Address,
88
BigInt,
99
log,
1010
ByteArray,
11-
} from '@graphprotocol/graph-ts'
11+
} from "@graphprotocol/graph-ts"
1212

1313
// Rinkeby agreement-1hive.open.aragonpm.eth:
1414
// const AGREEMENT_OPEN_APP_ID = '41dd0b999b443a19321f2f34fe8078d1af95a1487b49af4c2ca57fb9e3e5331e'
1515

1616
// xDai agreement.open.aragonpm.eth:
1717
const AGREEMENT_OPEN_APP_ID =
18-
'34c62f3aec3073826f39c2c35e9a1297d9dbf3cc77472283106f09eee9cf47bf'
18+
"34c62f3aec3073826f39c2c35e9a1297d9dbf3cc77472283106f09eee9cf47bf"
1919

2020
const AGREEMENT_APP_ID_LENGTH = AGREEMENT_OPEN_APP_ID.length
2121
const AGREEMENT_DISPUTE_METADATA_LENGTH = 64 // "[APP_ID][CHALLENGE_ID]" = 32 + 32
@@ -42,7 +42,7 @@ export function tryDecodingAgreementMetadata(dispute: Dispute): void {
4242
if (
4343
challengeData.reverted ||
4444
challengeData.value.value1.toHexString() ==
45-
'0x0000000000000000000000000000000000000000'
45+
"0x0000000000000000000000000000000000000000"
4646
)
4747
return
4848

package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.0.1",
44
"scripts": {
55
"draw-schema": "./scripts/draw-schema.sh",
6-
"build:graph": "./scripts/build-graph.sh",
6+
"build": "graph build",
77
"build:graph:rpc": "NETWORK=rpc npm run build:graph",
88
"build:graph:staging": "NETWORK=staging npm run build:graph",
99
"build:graph:rinkeby": "NETWORK=rinkeby npm run build:graph",
@@ -16,7 +16,7 @@
1616
"build:manifest:goerli": "NETWORK=goerli npm run build:manifest",
1717
"build:manifest:gnosis": "NETWORK=gnosis npm run build:manifest",
1818
"build:manifest:polygon": "NETWORK=polygon npm run build:manifest",
19-
"codegen": "./scripts/codegen.sh",
19+
"codegen": "graph codegen -o types",
2020
"codegen:rpc": "NETWORK=rpc npm run codegen",
2121
"codegen:ropsten": "NETWORK=ropsten npm run codegen",
2222
"codegen:staging": "NETWORK=staging npm run codegen",
@@ -30,7 +30,8 @@
3030
"deploy:rinkeby": "NETWORK=rinkeby npm run deploy",
3131
"deploy:goerli": "NETWORK=goerli npm run deploy",
3232
"deploy:gnosis": "NETWORK=gnosis npm run deploy",
33-
"deploy:polygon": "NETWORK=polygon npm run deploy"
33+
"deploy:polygon": "NETWORK=polygon npm run deploy",
34+
"graph": "graph"
3435
},
3536
"devDependencies": {
3637
"graphqlviz": "^3.1.0"
@@ -41,4 +42,4 @@
4142
"@graphprotocol/graph-cli": "^0.37.2",
4243
"@graphprotocol/graph-ts": "^0.29.3"
4344
}
44-
}
45+
}

scripts/build-graph.sh

-10
This file was deleted.

scripts/codegen.sh

-10
This file was deleted.

src/DisputeManager.ts

+18-16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { concat } from "../helpers/bytes"
12
import { buildId } from "../helpers/id"
23
import { createFeeMovement } from "./Treasury"
34
import { tryDecodingAgreementMetadata } from "../helpers/disputable"
@@ -7,7 +8,7 @@ import {
78
BigInt,
89
Address,
910
ethereum,
10-
log,
11+
ByteArray,
1112
} from "@graphprotocol/graph-ts"
1213
import {
1314
AdjudicationRound,
@@ -96,7 +97,7 @@ export function handleJurorDrafted(event: JurorDrafted): void {
9697

9798
export function handleDisputeStateChanged(event: DisputeStateChanged): void {
9899
let dispute = Dispute.load(event.params.disputeId.toString())!
99-
dispute.state = castDisputeState(Bytes.fromI32(event.params.state))
100+
dispute.state = castDisputeState(event.params.state)
100101
dispute.save()
101102

102103
updateRound(event.params.disputeId, dispute.lastRoundId, event)
@@ -107,7 +108,7 @@ export function handleDisputeStateChanged(event: DisputeStateChanged): void {
107108
event.params.disputeId,
108109
dispute.lastRoundId,
109110
event
110-
)
111+
)!
111112
round.draftedTermId = round.draftTermId.plus(round.delayedTerms)
112113
round.save()
113114
}
@@ -124,7 +125,7 @@ export function handleRulingAppealConfirmed(
124125
let manager = DisputeManager.bind(event.address)
125126
let dispute = new Dispute(event.params.disputeId.toString())
126127
let disputeResult = manager.getDispute(event.params.disputeId)
127-
dispute.state = castDisputeState(new Bytes(disputeResult.value2))
128+
dispute.state = castDisputeState(disputeResult.value2)
128129
dispute.lastRoundId = disputeResult.value4
129130
dispute.save()
130131

@@ -199,7 +200,7 @@ function updateRound(
199200
roundNumber: BigInt,
200201
event: ethereum.Event
201202
): void {
202-
let round = loadOrCreateRound(disputeId, roundNumber, event)
203+
let round = loadOrCreateRound(disputeId, roundNumber, event)!
203204
let manager = DisputeManager.bind(event.address)
204205
let result = manager.getRound(disputeId, roundNumber)
205206
round.number = roundNumber
@@ -212,7 +213,7 @@ function updateRound(
212213
round.settledPenalties = result.value5
213214
round.collectedTokens = result.value6
214215
round.coherentJurors = result.value7
215-
round.state = castAdjudicationState(Bytes.fromI32(result.value8))
216+
round.state = castAdjudicationState(result.value8)
216217
round.stateInt = result.value8
217218
round.save()
218219
}
@@ -221,7 +222,7 @@ function loadOrCreateRound(
221222
disputeId: BigInt,
222223
roundNumber: BigInt,
223224
event: ethereum.Event
224-
): AdjudicationRound {
225+
): AdjudicationRound | null {
225226
let id = buildRoundId(disputeId, roundNumber).toString()
226227
let round = AdjudicationRound.load(id)
227228

@@ -234,7 +235,10 @@ function loadOrCreateRound(
234235
return round
235236
}
236237

237-
function createJurorDispute(disputeId: BigInt, juror: Address): JurorDispute {
238+
function createJurorDispute(
239+
disputeId: BigInt,
240+
juror: Address
241+
): JurorDispute | null {
238242
let id = buildJurorDisputeId(disputeId, juror).toString()
239243
let jurorDispute = JurorDispute.load(id)
240244

@@ -253,7 +257,7 @@ function updateAppeal(
253257
roundNumber: BigInt,
254258
event: ethereum.Event
255259
): void {
256-
let appeal = loadOrCreateAppeal(disputeId, roundNumber, event)
260+
let appeal = loadOrCreateAppeal(disputeId, roundNumber, event)!
257261
let manager = DisputeManager.bind(event.address)
258262
let result = manager.getAppeal(disputeId, roundNumber)
259263
let nextRound = manager.getNextRoundDetails(disputeId, roundNumber)
@@ -364,7 +368,7 @@ function loadOrCreateAppeal(
364368
disputeId: BigInt,
365369
roundNumber: BigInt,
366370
event: ethereum.Event
367-
): Appeal {
371+
): Appeal | null {
368372
let id = buildAppealId(disputeId, roundNumber).toString()
369373
let appeal = Appeal.load(id)
370374

@@ -414,12 +418,10 @@ export function decodeDisputeRoundId(disputeRoundId: BigInt): BigInt[] {
414418
}
415419

416420
export function buildDraftId(roundId: BigInt, juror: Address): string {
417-
// @ts-ignore BigInt is actually a BytesArray under the hood
418421
return crypto.keccak256(Bytes.fromBigInt(roundId).concat(juror)).toHexString()
419422
}
420423

421424
export function buildJurorDisputeId(disputeId: BigInt, juror: Address): string {
422-
// @ts-ignore BigInt is actually a BytesArray under the hood
423425
return crypto
424426
.keccak256(Bytes.fromBigInt(disputeId).concat(juror))
425427
.toHexString()
@@ -430,8 +432,8 @@ function buildAppealId(disputeId: BigInt, roundId: BigInt): BigInt {
430432
return buildRoundId(disputeId, roundId)
431433
}
432434

433-
function castDisputeState(state: Bytes): string {
434-
switch (state.toI32()) {
435+
function castDisputeState(state: i32): string {
436+
switch (state) {
435437
case 0:
436438
return "Drafting"
437439
case 1:
@@ -443,8 +445,8 @@ function castDisputeState(state: Bytes): string {
443445
}
444446
}
445447

446-
function castAdjudicationState(state: Bytes): string {
447-
switch (state.toI32()) {
448+
function castAdjudicationState(state: i32): string {
449+
switch (state) {
448450
case 0:
449451
return "Invalid"
450452
case 1:

0 commit comments

Comments
 (0)