|
7 | 7 | KlerosCoreNeo,
|
8 | 8 | SortitionModuleNeo,
|
9 | 9 | DisputeKitClassic,
|
| 10 | + ChainlinkRNG, |
10 | 11 | } from "../typechain-types";
|
11 | 12 | import request from "graphql-request";
|
12 | 13 | import env from "./utils/env";
|
@@ -61,10 +62,11 @@ const getContracts = async () => {
|
61 | 62 | default:
|
62 | 63 | throw new Error("Invalid core type, must be one of base, neo");
|
63 | 64 | }
|
| 65 | + const chainlinkRng = await ethers.getContractOrNull<ChainlinkRNG>("ChainlinkRNG"); |
64 | 66 | const randomizerRng = await ethers.getContractOrNull<RandomizerRNG>("RandomizerRNG");
|
65 | 67 | const blockHashRNG = await ethers.getContractOrNull<BlockHashRNG>("BlockHashRNG");
|
66 | 68 | const pnk = (await ethers.getContract("PNK")) as PNK;
|
67 |
| - return { core, sortition, randomizerRng, blockHashRNG, disputeKitClassic, pnk }; |
| 69 | + return { core, sortition, chainlinkRng, randomizerRng, blockHashRNG, disputeKitClassic, pnk }; |
68 | 70 | };
|
69 | 71 |
|
70 | 72 | type Contribution = {
|
@@ -181,11 +183,21 @@ const handleError = (e: any) => {
|
181 | 183 | };
|
182 | 184 |
|
183 | 185 | const isRngReady = async () => {
|
184 |
| - const { randomizerRng, blockHashRNG, sortition } = await getContracts(); |
| 186 | + const { chainlinkRng, randomizerRng, blockHashRNG, sortition } = await getContracts(); |
185 | 187 | const currentRng = await sortition.rng();
|
186 |
| - if (currentRng === randomizerRng?.target) { |
187 |
| - const requesterID = await randomizerRng.requesterToID(sortition.target); |
188 |
| - const n = await randomizerRng.randomNumbers(requesterID); |
| 188 | + if (currentRng === chainlinkRng?.target) { |
| 189 | + const requestID = await chainlinkRng.lastRequestId(); |
| 190 | + const n = await chainlinkRng.randomNumbers(requestID); |
| 191 | + if (Number(n) === 0) { |
| 192 | + logger.info("ChainlinkRNG is NOT ready yet"); |
| 193 | + return false; |
| 194 | + } else { |
| 195 | + logger.info(`ChainlinkRNG is ready: ${n.toString()}`); |
| 196 | + return true; |
| 197 | + } |
| 198 | + } else if (currentRng === randomizerRng?.target) { |
| 199 | + const requestID = await randomizerRng.lastRequestId(); |
| 200 | + const n = await randomizerRng.randomNumbers(requestID); |
189 | 201 | if (Number(n) === 0) {
|
190 | 202 | logger.info("RandomizerRNG is NOT ready yet");
|
191 | 203 | return false;
|
|
0 commit comments