Skip to content

Commit 291c30f

Browse files
committed
fix: fixed cross-chain MetaEvidence arbitrableJsonRpcUrl
1 parent d3ecd6a commit 291c30f

File tree

4 files changed

+784
-903
lines changed

4 files changed

+784
-903
lines changed

docs/archon-arbitrable.rst

+12-11
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,18 @@ Parameters
138138

139139
The options parameter can include:
140140

141-
================ ====== ======================================================
142-
Key Type Description
143-
================ ====== ======================================================
144-
strict bool If true, an error will throw if hash or chain ID validations fail.
145-
strictHashes bool [DEPRECATED] If true, an error will throw if hash validations fail.
146-
customHashFn fn Hashing function that should be used to validate the hashes.
147-
fromBlock int The block where we start searching for event logs.
148-
toBlock int The block where we will stop searching for event logs.
149-
filters object Additional filters for event logs.
150-
scriptParameters object Parameters to pass to sandboxed script.
151-
================ ====== ======================================================
141+
================ ======== ======================================================
142+
Key Type Description
143+
================ ======== ======================================================
144+
`strict` bool If true, an error will throw if hash or chain ID validations fail.
145+
`strictHashes` bool [DEPRECATED] If true, an error will throw if hash validations fail.
146+
`customHashFn` fn Hashing function that should be used to validate the hashes.
147+
`fromBlock` int The block where we start searching for event logs.
148+
`toBlock` int The block where we will stop searching for event logs.
149+
`filters` object Additional filters for event logs.
150+
`scriptParameters` object Parameters to pass to sandboxed script.
151+
`getJsonRpcUrl` function A callback `(chainID: number) => string` to get a JSON-RPC URL for the given chain ID. Required in cross-chain MetaEvidece.
152+
================ ======== ======================================================
152153

153154
.. tip:: Use :ref:`getDispute <getDispute>` to get the metaEvidenceID for a dispute.
154155

src/standards/Arbitrable.js

+47-11
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Arbitrable extends StandardContract {
4848
* @param {string} contractAddress - The address of the arbitrable contract.
4949
* @param {string} arbitratorAddress - The address of the arbitrator contract.
5050
* @param {number} evidenceGroupID - The index of the evidence group.
51-
* @param {object} options - Additional paramaters. Includes fromBlock, toBlock, filters, strictHashes, strict
51+
* @param {object} options - Additional paramaters. Includes fromBlock, toBlock, filters, strict
5252
* @returns {object[]} An array of evidence objects
5353
*/
5454
getEvidence = async (
@@ -84,7 +84,6 @@ class Arbitrable extends StandardContract {
8484
const { file: evidenceJSON, isValid: evidenceJSONValid } = await validateFileFromURI(evidenceURI, {
8585
preValidated,
8686
strict,
87-
strictHashes: options.strictHashes,
8887
customHashFn: options.customHashFn,
8988
});
9089

@@ -98,7 +97,6 @@ class Arbitrable extends StandardContract {
9897
await validateFileFromURI(evidenceURI, {
9998
preValidated,
10099
strict,
101-
strictHashes: options.strictHashes,
102100
hash: evidenceJSON.fileHash,
103101
customHashFn: options.customHashFn,
104102
})
@@ -144,14 +142,15 @@ class Arbitrable extends StandardContract {
144142
* NOTE: If more than one MetaEvidence with the same metaEvidenceID is found it will return the 1st one.
145143
* @param {string} contractAddress - The address of the Arbitrable contract.
146144
* @param {number} metaEvidenceID - The identifier of the metaEvidence log.
147-
* @param {object} options - Additional paramaters. Includes fromBlock, toBlock, strictHashes
145+
* @param {object} options - Additional paramaters. Includes fromBlock, toBlock, strict, getJsonRpcUrl
148146
* @returns {object} The metaEvidence object
149147
*/
150-
getMetaEvidence = async (
148+
async getMetaEvidence(
151149
contractAddress = isRequired("contractAddress"),
152150
metaEvidenceID = isRequired("metaEvidenceID"),
153151
options = {}
154-
) => {
152+
) {
153+
const { getJsonRpcUrl = () => {} } = options;
155154
const strict = options.strict || options.strictHashes;
156155
const contractInstance = this._loadContractInstance(contractAddress);
157156

@@ -178,7 +177,6 @@ class Arbitrable extends StandardContract {
178177
const { file: _metaEvidenceJSON, isValid: metaEvidenceJSONValid } = await validateFileFromURI(metaEvidenceUri, {
179178
preValidated,
180179
strict,
181-
strictHashes: options.strictHashes,
182180
customHashFn: options.customHashFn,
183181
});
184182

@@ -209,7 +207,6 @@ class Arbitrable extends StandardContract {
209207
const script = await validateFileFromURI(scriptURI, {
210208
preValidated,
211209
strict,
212-
strictHashes: options.strictHashes,
213210
hash: metaEvidenceJSON.dynamicScriptHash,
214211
customHashFn: options.customHashFn,
215212
});
@@ -246,10 +243,51 @@ class Arbitrable extends StandardContract {
246243
...scriptParameters,
247244
};
248245

246+
if (injectedParameters.arbitrableContractAddress === undefined) {
247+
injectedParameters.arbitrableContractAddress = contractAddress;
248+
}
249+
250+
if (injectedParameters.arbitratorChainID !== undefined) {
251+
injectedParameters.arbitratorJsonRpcUrl =
252+
injectedParameters.arbitratorJsonRpcUrl || getJsonRpcUrl(injectedParameters.arbitratorChainID);
253+
}
254+
249255
if (injectedParameters.arbitrableChainID === undefined) {
250256
injectedParameters.arbitrableChainID = injectedParameters.arbitratorChainID;
251257
}
252258

259+
if (
260+
injectedParameters.arbitrableChainID !== undefined &&
261+
injectedParameters.arbitrableJsonRpcUrl === undefined
262+
) {
263+
if (injectedParameters.arbitrableChainID === injectedParameters.arbitratorChainID) {
264+
injectedParameters.arbitrableJsonRpcUrl = injectedParameters.arbitratorJsonRpcUrl;
265+
}
266+
267+
injectedParameters.arbitrableJsonRpcUrl =
268+
injectedParameters.arbitrableJsonRpcUrl || getJsonRpcUrl(injectedParameters.arbitrableChainID);
269+
}
270+
271+
if (
272+
injectedParameters.arbitratorChainID !== undefined &&
273+
injectedParameters.arbitratorJsonRpcUrl === undefined
274+
) {
275+
console.warn(
276+
`Could not obtain a valid 'arbitratorJsonRpcUrl' for chain ID ${injectedParameters.arbitratorChainID} on the Arbitrator side.
277+
You should either provide it directly or provide a 'options.getJsonRpcUrl(chainID: number) => string' callback.`
278+
);
279+
}
280+
281+
if (
282+
injectedParameters.arbitrableChainID !== undefined &&
283+
injectedParameters.arbitrableJsonRpcUrl === undefined
284+
) {
285+
console.warn(
286+
`Could not obtain a valid 'arbitrableJsonRpcUrl' for chain ID ${injectedParameters.arbitrableChainID} on the Arbitrable side.
287+
You should either provide it directly or provide a 'options.getJsonRpcUrl(chainID: number) => string' callback.`
288+
);
289+
}
290+
253291
const metaEvidenceEdits = await fetchDataFromScript(script.file, injectedParameters);
254292

255293
metaEvidenceJSON = {
@@ -277,7 +315,6 @@ class Arbitrable extends StandardContract {
277315
await validateFileFromURI(fileURI, {
278316
preValidated,
279317
strict,
280-
strictHashes: options.strictHashes,
281318
hash: metaEvidenceJSON.fileHash,
282319
customHashFn: options.customHashFn,
283320
})
@@ -303,7 +340,6 @@ class Arbitrable extends StandardContract {
303340
interfaceValid = (
304341
await validateFileFromURI(disputeInterfaceURI, {
305342
strict,
306-
strictHashes: options.strictHashes,
307343
hash: metaEvidenceJSON.evidenceDisplayInterfaceHash,
308344
customHashFn: options.customHashFn,
309345
})
@@ -326,7 +362,7 @@ class Arbitrable extends StandardContract {
326362
blockNumber: metaEvidenceLog.blockNumber,
327363
transactionHash: metaEvidenceLog.transactionHash,
328364
};
329-
};
365+
}
330366

331367
/**
332368
* Fetch the ruling for a dispute.

src/utils/frame-loader.js

+43-46
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,12 @@
1-
import iframe from "iframe";
2-
31
export default function fetchDataFromScript(scriptString, scriptParameters) {
42
return typeof window !== "undefined"
53
? fetchDataFromScriptIframe(scriptString, scriptParameters)
64
: fetchDataFromScriptSandbox(scriptString, scriptParameters);
75
}
86

9-
const fetchDataFromScriptSandbox =
10-
process.env.NODE_ENV !== "production"
11-
? async (scriptString, scriptParameters) => {
12-
const { default: Sandbox } = await import("v8-sandbox");
13-
const sandbox = new Sandbox();
14-
15-
const code = `
16-
${scriptString}
17-
18-
let resolveScript
19-
let rejectScript
20-
let scriptParameters = JSON.parse(stringifiedScriptParameters)
21-
22-
const returnPromise = new Promise((resolve, reject) => {
23-
resolveScript = resolve
24-
rejectScript = reject
25-
})
26-
27-
getMetaEvidence()
28-
29-
returnPromise.then((metaEvidence) => {
30-
setResult({ value: metaEvidence })
31-
}).catch((err) => {
32-
setResult({ error: err })
33-
})`;
34-
35-
const { error, value } = await sandbox.execute({
36-
code,
37-
globals: {
38-
stringifiedScriptParameters: JSON.stringify(scriptParameters || {}),
39-
},
40-
timeout: 5000,
41-
});
42-
43-
await sandbox.shutdown();
44-
45-
if (error) {
46-
throw error;
47-
}
48-
49-
return value;
50-
}
51-
: async () => ({});
52-
537
const fetchDataFromScriptIframe = async (scriptString, scriptParameters) => {
8+
const { default: iframe } = await import("iframe");
9+
5410
let resolver;
5511
const returnPromise = new Promise((resolve) => {
5612
resolver = resolve;
@@ -90,3 +46,44 @@ const fetchDataFromScriptIframe = async (scriptString, scriptParameters) => {
9046
_.iframe.style.display = "none";
9147
return returnPromise;
9248
};
49+
50+
const fetchDataFromScriptSandbox = async (scriptString, scriptParameters) => {
51+
const { default: Sandbox } = await import("v8-sandbox");
52+
const sandbox = new Sandbox();
53+
54+
const code = `
55+
${scriptString}
56+
57+
let resolveScript
58+
let rejectScript
59+
let scriptParameters = JSON.parse(stringifiedScriptParameters)
60+
61+
const returnPromise = new Promise((resolve, reject) => {
62+
resolveScript = resolve
63+
rejectScript = reject
64+
})
65+
66+
getMetaEvidence()
67+
68+
returnPromise.then((metaEvidence) => {
69+
setResult({ value: metaEvidence })
70+
}).catch((err) => {
71+
setResult({ error: err })
72+
})`;
73+
74+
const { error, value } = await sandbox.execute({
75+
code,
76+
globals: {
77+
stringifiedScriptParameters: JSON.stringify(scriptParameters || {}),
78+
},
79+
timeout: 5000,
80+
});
81+
82+
await sandbox.shutdown();
83+
84+
if (error) {
85+
throw error;
86+
}
87+
88+
return value;
89+
};

0 commit comments

Comments
 (0)