@@ -9,7 +9,15 @@ import {
9
9
CommitCast ,
10
10
} from "../generated/DisputeKitClassic/DisputeKitClassic" ;
11
11
import { KlerosCore } from "../generated/KlerosCore/KlerosCore" ;
12
- import { ClassicDispute , ClassicJustification , ClassicRound , ClassicVote , Dispute } from "../generated/schema" ;
12
+ import {
13
+ ClassicDispute ,
14
+ ClassicJustification ,
15
+ ClassicRound ,
16
+ ClassicVote ,
17
+ Dispute ,
18
+ DisputeKit ,
19
+ Round ,
20
+ } from "../generated/schema" ;
13
21
import { ensureClassicContributionFromEvent } from "./entities/ClassicContribution" ;
14
22
import { createClassicDisputeFromEvent } from "./entities/ClassicDispute" ;
15
23
import {
@@ -19,23 +27,31 @@ import {
19
27
updateCountsAndGetCurrentRuling ,
20
28
} from "./entities/ClassicRound" ;
21
29
import { ensureClassicVote } from "./entities/ClassicVote" ;
22
- import { ONE , ZERO } from "./utils" ;
23
-
24
- export const DISPUTEKIT_ID = "1" ;
30
+ import { ONE , ZERO , extractDisputeKitIDFromExtraData } from "./utils" ;
25
31
26
32
export function handleDisputeCreation ( event : DisputeCreation ) : void {
27
33
const disputeID = event . params . _coreDisputeID . toString ( ) ;
28
- createClassicDisputeFromEvent ( event ) ;
34
+ const disputeKitID = extractDisputeKitIDFromExtraData ( event . params . _extraData ) ;
35
+ createClassicDisputeFromEvent ( event , disputeKitID ) ;
29
36
const numberOfChoices = event . params . _numberOfChoices ;
30
- createClassicRound ( disputeID , numberOfChoices , ZERO ) ;
37
+ createClassicRound ( disputeID , numberOfChoices , ZERO , disputeKitID ) ;
31
38
}
32
39
33
40
export function handleCommitCast ( event : CommitCast ) : void {
34
- const coreDisputeID = event . params . _coreDisputeID ;
35
- const coreDispute = Dispute . load ( coreDisputeID . toString ( ) ) ;
36
- const classicDisputeID = `${ DISPUTEKIT_ID } -${ coreDisputeID } ` ;
41
+ const coreDisputeID = event . params . _coreDisputeID . toString ( ) ;
42
+ const coreDispute = Dispute . load ( coreDisputeID ) ;
43
+ if ( ! coreDispute ) return ;
44
+
45
+ const coreCurrentRound = Round . load ( coreDispute . currentRound ) ;
46
+ if ( ! coreCurrentRound ) return ;
47
+
48
+ const disputeKitID = coreCurrentRound . disputeKit ;
49
+
50
+ const classicDisputeID = `${ disputeKitID } -${ coreDisputeID } ` ;
51
+
37
52
const classicDispute = ClassicDispute . load ( classicDisputeID ) ;
38
- if ( ! classicDispute || ! coreDispute ) return ;
53
+ if ( ! classicDispute ) return ;
54
+
39
55
const currentLocalRoundID = classicDispute . id + "-" + classicDispute . currentLocalRoundIndex . toString ( ) ;
40
56
const voteIDs = event . params . _voteIDs ;
41
57
for ( let i = 0 ; i < voteIDs . length ; i ++ ) {
@@ -55,9 +71,18 @@ export function handleVoteCast(event: VoteCast): void {
55
71
const juror = event . params . _juror . toHexString ( ) ;
56
72
const coreDisputeID = event . params . _coreDisputeID . toString ( ) ;
57
73
const coreDispute = Dispute . load ( coreDisputeID ) ;
58
- const classicDisputeID = `${ DISPUTEKIT_ID } -${ coreDisputeID } ` ;
74
+ if ( ! coreDispute ) return ;
75
+
76
+ const coreCurrentRound = Round . load ( coreDispute . currentRound ) ;
77
+ if ( ! coreCurrentRound ) return ;
78
+
79
+ const disputeKitID = coreCurrentRound . disputeKit ;
80
+
81
+ const classicDisputeID = `${ disputeKitID } -${ coreDisputeID } ` ;
82
+
59
83
const classicDispute = ClassicDispute . load ( classicDisputeID ) ;
60
- if ( ! classicDispute || ! coreDispute ) return ;
84
+ if ( ! classicDispute ) return ;
85
+
61
86
const choice = event . params . _choice ;
62
87
const currentLocalRoundID = classicDispute . id + "-" + classicDispute . currentLocalRoundIndex . toString ( ) ;
63
88
const voteIDs = event . params . _voteIDs ;
@@ -70,6 +95,7 @@ export function handleVoteCast(event: VoteCast): void {
70
95
justification . transactionHash = event . transaction . hash . toHexString ( ) ;
71
96
justification . timestamp = event . block . timestamp ;
72
97
justification . save ( ) ;
98
+
73
99
const currentRulingInfo = updateCountsAndGetCurrentRuling (
74
100
currentLocalRoundID ,
75
101
choice ,
@@ -78,6 +104,7 @@ export function handleVoteCast(event: VoteCast): void {
78
104
coreDispute . currentRuling = currentRulingInfo . ruling ;
79
105
coreDispute . tied = currentRulingInfo . tied ;
80
106
coreDispute . save ( ) ;
107
+
81
108
let classicVote : ClassicVote ;
82
109
for ( let i = 0 ; i < voteIDs . length ; i ++ ) {
83
110
classicVote = ensureClassicVote ( currentLocalRoundID , juror , voteIDs [ i ] , coreDispute ) ;
@@ -97,7 +124,16 @@ export function handleChoiceFunded(event: ChoiceFunded): void {
97
124
const coreDisputeID = event . params . _coreDisputeID . toString ( ) ;
98
125
const coreRoundIndex = event . params . _coreRoundID . toString ( ) ;
99
126
const choice = event . params . _choice ;
100
- const roundID = `${ DISPUTEKIT_ID } -${ coreDisputeID } -${ coreRoundIndex } ` ;
127
+
128
+ const coreDispute = Dispute . load ( coreDisputeID ) ;
129
+ if ( ! coreDispute ) return ;
130
+
131
+ const roundId = `${ coreDisputeID } -${ coreRoundIndex } ` ;
132
+ const coreRound = Round . load ( roundId ) ;
133
+ if ( ! coreRound ) return ;
134
+ const disputeKitID = coreRound . disputeKit ;
135
+
136
+ const roundID = `${ disputeKitID } -${ coreDisputeID } -${ coreRoundIndex } ` ;
101
137
102
138
const localRound = ClassicRound . load ( roundID ) ;
103
139
if ( ! localRound ) return ;
@@ -123,13 +159,13 @@ export function handleChoiceFunded(event: ChoiceFunded): void {
123
159
124
160
localRound . feeRewards = localRound . feeRewards . minus ( appealCost ) ;
125
161
126
- const localDispute = ClassicDispute . load ( `${ DISPUTEKIT_ID } -${ coreDisputeID } ` ) ;
162
+ const localDispute = ClassicDispute . load ( `${ disputeKitID } -${ coreDisputeID } ` ) ;
127
163
if ( ! localDispute ) return ;
128
164
const newRoundIndex = localDispute . currentLocalRoundIndex . plus ( ONE ) ;
129
165
const numberOfChoices = localDispute . numberOfChoices ;
130
166
localDispute . currentLocalRoundIndex = newRoundIndex ;
131
167
localDispute . save ( ) ;
132
- createClassicRound ( coreDisputeID , numberOfChoices , newRoundIndex ) ;
168
+ createClassicRound ( coreDisputeID , numberOfChoices , newRoundIndex , disputeKitID ) ;
133
169
}
134
170
135
171
localRound . save ( ) ;
@@ -144,7 +180,16 @@ export function handleWithdrawal(event: Withdrawal): void {
144
180
// check if all appeal fees have been withdrawn
145
181
const coreDisputeID = event . params . _coreDisputeID . toString ( ) ;
146
182
const coreRoundIndex = event . params . _coreRoundID . toString ( ) ;
147
- const roundID = `${ DISPUTEKIT_ID } -${ coreDisputeID } -${ coreRoundIndex } ` ;
183
+
184
+ const coreDispute = Dispute . load ( coreDisputeID ) ;
185
+ if ( ! coreDispute ) return ;
186
+
187
+ const roundId = `${ coreDisputeID } -${ coreRoundIndex } ` ;
188
+ const coreRound = Round . load ( roundId ) ;
189
+ if ( ! coreRound ) return ;
190
+ const disputeKitID = coreRound . disputeKit ;
191
+
192
+ const roundID = `${ disputeKitID } -${ coreDisputeID } -${ coreRoundIndex } ` ;
148
193
149
194
const localRound = ClassicRound . load ( roundID ) ;
150
195
if ( ! localRound ) return ;
0 commit comments