@@ -9,15 +9,7 @@ import {
9
9
CommitCast ,
10
10
} from "../generated/DisputeKitClassic/DisputeKitClassic" ;
11
11
import { KlerosCore } from "../generated/KlerosCore/KlerosCore" ;
12
- import {
13
- ClassicDispute ,
14
- ClassicJustification ,
15
- ClassicRound ,
16
- ClassicVote ,
17
- Dispute ,
18
- DisputeKit ,
19
- Round ,
20
- } from "../generated/schema" ;
12
+ import { ClassicDispute , ClassicJustification , ClassicRound , ClassicVote , Dispute , Round } from "../generated/schema" ;
21
13
import { ensureClassicContributionFromEvent } from "./entities/ClassicContribution" ;
22
14
import { createClassicDisputeFromEvent } from "./entities/ClassicDispute" ;
23
15
import {
@@ -27,14 +19,19 @@ import {
27
19
updateCountsAndGetCurrentRuling ,
28
20
} from "./entities/ClassicRound" ;
29
21
import { ensureClassicVote } from "./entities/ClassicVote" ;
30
- import { ONE , ZERO , extractDisputeKitIDFromExtraData } from "./utils" ;
22
+ import { ONE , extractDisputeKitIDFromExtraData } from "./utils" ;
31
23
32
24
export function handleDisputeCreation ( event : DisputeCreation ) : void {
33
25
const disputeID = event . params . _coreDisputeID . toString ( ) ;
34
26
const disputeKitID = extractDisputeKitIDFromExtraData ( event . params . _extraData ) ;
35
- createClassicDisputeFromEvent ( event , disputeKitID ) ;
36
- const numberOfChoices = event . params . _numberOfChoices ;
37
- createClassicRound ( disputeID , numberOfChoices , ZERO , disputeKitID ) ;
27
+
28
+ const disputeKitClassic = DisputeKitClassic . bind ( event . address ) ;
29
+ const klerosCore = KlerosCore . bind ( disputeKitClassic . core ( ) ) ;
30
+ const totalRounds = klerosCore . getNumberOfRounds ( event . params . _coreDisputeID ) ;
31
+ const newRoundIndex = totalRounds . minus ( ONE ) ;
32
+
33
+ createClassicDisputeFromEvent ( event , disputeKitID , newRoundIndex ) ;
34
+ createClassicRound ( disputeID , event . params . _numberOfChoices , newRoundIndex , disputeKitID ) ;
38
35
}
39
36
40
37
export function handleCommitCast ( event : CommitCast ) : void {
@@ -156,16 +153,23 @@ export function handleChoiceFunded(event: ChoiceFunded): void {
156
153
const numberOfRounds = klerosCore . getNumberOfRounds ( BigInt . fromString ( coreDisputeID ) ) ;
157
154
const roundInfo = klerosCore . getRoundInfo ( BigInt . fromString ( coreDisputeID ) , numberOfRounds . minus ( ONE ) ) ;
158
155
const appealCost = roundInfo . totalFeesForJurors ;
156
+ const currentDisputeKitID = roundInfo . disputeKitID ;
159
157
160
158
localRound . feeRewards = localRound . feeRewards . minus ( appealCost ) ;
161
159
160
+ const newRoundInfo = klerosCore . getRoundInfo ( BigInt . fromString ( coreDisputeID ) , numberOfRounds ) ;
161
+ const newDisputeKitID = newRoundInfo . disputeKitID ;
162
+
162
163
const localDispute = ClassicDispute . load ( `${ disputeKitID } -${ coreDisputeID } ` ) ;
163
164
if ( ! localDispute ) return ;
164
- const newRoundIndex = localDispute . currentLocalRoundIndex . plus ( ONE ) ;
165
- const numberOfChoices = localDispute . numberOfChoices ;
166
- localDispute . currentLocalRoundIndex = newRoundIndex ;
167
- localDispute . save ( ) ;
168
- createClassicRound ( coreDisputeID , numberOfChoices , newRoundIndex , disputeKitID ) ;
165
+
166
+ if ( currentDisputeKitID === newDisputeKitID ) {
167
+ const newRoundIndex = localDispute . currentLocalRoundIndex . plus ( ONE ) ;
168
+ const numberOfChoices = localDispute . numberOfChoices ;
169
+ localDispute . currentLocalRoundIndex = newRoundIndex ;
170
+ localDispute . save ( ) ;
171
+ createClassicRound ( coreDisputeID , numberOfChoices , newRoundIndex , disputeKitID ) ;
172
+ }
169
173
}
170
174
171
175
localRound . save ( ) ;
0 commit comments