Skip to content

Commit c8bc752

Browse files
committed
refactor(subgraph): simplify handleDraw
1 parent 1d3022d commit c8bc752

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

subgraph/src/KlerosCore.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { BigInt, store, Entity, Value } from "@graphprotocol/graph-ts";
1+
import {
2+
Address,
3+
BigInt,
4+
Entity,
5+
Value,
6+
store,
7+
} from "@graphprotocol/graph-ts";
28
import {
39
KlerosCore,
410
AppealDecision,
@@ -94,20 +100,24 @@ export function handleDraw(event: DrawEvent): void {
94100
draw.save();
95101
const dispute = Dispute.load(disputeID.toString());
96102
if (dispute) {
97-
const jurorTokens = JurorTokensPerSubcourt.load(
98-
`${drawnAddress.toHexString()}-${dispute.subcourtID.toString()}`
103+
updateJurorBalance(
104+
drawnAddress.toHexString(), dispute.subcourtID.toString(), event
99105
);
100-
if (jurorTokens) {
101-
const contract = KlerosCore.bind(event.address);
102-
const jurorBalance = contract.getJurorBalance(
103-
drawnAddress, BigInt.fromString(dispute.subcourtID)
104-
);
105-
jurorTokens.locked = jurorBalance.value1;
106-
jurorTokens.save();
107-
}
108106
}
109107
}
110108

109+
function updateJurorBalance(
110+
address: string, subcourt: string, event: DrawEvent
111+
): void {
112+
const jurorTokens = new JurorTokensPerSubcourt(`${address}-${subcourt}`);
113+
const contract = KlerosCore.bind(event.address);
114+
const jurorBalance = contract.getJurorBalance(
115+
Address.fromString(address), BigInt.fromString(subcourt)
116+
);
117+
jurorTokens.locked = jurorBalance.value1;
118+
jurorTokens.save();
119+
}
120+
111121
export function handleStakeSet(event: StakeSet): void {
112122
const jurorAddress = event.params._address.toHexString();
113123
let juror = Juror.load(jurorAddress);

0 commit comments

Comments
 (0)