@atomiqlabs/chain-starknet 8.4.3 → 8.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -214,9 +214,16 @@ class StarknetBtcRelay extends StarknetContractBase_1.StarknetContractBase {
|
|
|
214
214
|
return null;
|
|
215
215
|
const [storedBlockHeader, commitHash] = result;
|
|
216
216
|
//Check if block is part of the main chain
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
217
|
+
try {
|
|
218
|
+
const chainCommitment = await this.contract.get_commit_hash(storedBlockHeader.getBlockheight());
|
|
219
|
+
if (BigInt(chainCommitment) !== BigInt(commitHash))
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
catch (e) {
|
|
223
|
+
if (e.baseError?.code === 40 && e.baseError?.revert_error != null)
|
|
224
|
+
return null;
|
|
225
|
+
throw e;
|
|
226
|
+
}
|
|
220
227
|
logger.debug("retrieveLogAndBlockheight(): block found," +
|
|
221
228
|
" commit hash: " + (0, Utils_1.toHex)(commitHash) + " blockhash: " + blockData.blockhash + " current btc relay height: " + blockHeight);
|
|
222
229
|
return { header: storedBlockHeader, height: blockHeight };
|
|
@@ -230,9 +237,16 @@ class StarknetBtcRelay extends StarknetContractBase_1.StarknetContractBase {
|
|
|
230
237
|
return null;
|
|
231
238
|
const [storedBlockHeader, commitHash] = result;
|
|
232
239
|
//Check if block is part of the main chain
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
240
|
+
try {
|
|
241
|
+
const chainCommitment = await this.contract.get_commit_hash(storedBlockHeader.getBlockheight());
|
|
242
|
+
if (BigInt(chainCommitment) !== BigInt(commitHash))
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
catch (e) {
|
|
246
|
+
if (e.baseError?.code === 40 && e.baseError?.revert_error != null)
|
|
247
|
+
return null;
|
|
248
|
+
throw e;
|
|
249
|
+
}
|
|
236
250
|
logger.debug("retrieveLogByCommitHash(): block found," +
|
|
237
251
|
" commit hash: " + commitmentHash + " blockhash: " + blockData.blockhash + " height: " + storedBlockHeader.getBlockheight());
|
|
238
252
|
return storedBlockHeader;
|
|
@@ -246,8 +260,12 @@ class StarknetBtcRelay extends StarknetContractBase_1.StarknetContractBase {
|
|
|
246
260
|
const blockHashHex = storedHeader.getBlockHash().toString("hex");
|
|
247
261
|
const commitHash = event.params.commit_hash;
|
|
248
262
|
const [isInBtcMainChain, btcRelayCommitHash] = await Promise.all([
|
|
249
|
-
this._bitcoinRpc.isInMainChain(blockHashHex)
|
|
250
|
-
this.contract.get_commit_hash(storedHeader.getBlockheight())
|
|
263
|
+
this._bitcoinRpc.isInMainChain(blockHashHex),
|
|
264
|
+
this.contract.get_commit_hash(storedHeader.getBlockheight()).catch(e => {
|
|
265
|
+
if (e.baseError?.code === 40 && e.baseError?.revert_error != null)
|
|
266
|
+
return 0n;
|
|
267
|
+
throw e;
|
|
268
|
+
})
|
|
251
269
|
]);
|
|
252
270
|
if (!isInBtcMainChain)
|
|
253
271
|
return null;
|
package/package.json
CHANGED
|
@@ -282,8 +282,13 @@ export class StarknetBtcRelay<B extends BtcBlock>
|
|
|
282
282
|
const [storedBlockHeader, commitHash] = result;
|
|
283
283
|
|
|
284
284
|
//Check if block is part of the main chain
|
|
285
|
-
|
|
286
|
-
|
|
285
|
+
try {
|
|
286
|
+
const chainCommitment = await this.contract.get_commit_hash(storedBlockHeader.getBlockheight());
|
|
287
|
+
if(BigInt(chainCommitment)!==BigInt(commitHash)) return null;
|
|
288
|
+
} catch (e: any) {
|
|
289
|
+
if(e.baseError?.code===40 && e.baseError?.revert_error!=null) return null;
|
|
290
|
+
throw e;
|
|
291
|
+
}
|
|
287
292
|
|
|
288
293
|
logger.debug("retrieveLogAndBlockheight(): block found," +
|
|
289
294
|
" commit hash: "+toHex(commitHash)+" blockhash: "+blockData.blockhash+" current btc relay height: "+blockHeight);
|
|
@@ -301,8 +306,13 @@ export class StarknetBtcRelay<B extends BtcBlock>
|
|
|
301
306
|
const [storedBlockHeader, commitHash] = result;
|
|
302
307
|
|
|
303
308
|
//Check if block is part of the main chain
|
|
304
|
-
|
|
305
|
-
|
|
309
|
+
try {
|
|
310
|
+
const chainCommitment = await this.contract.get_commit_hash(storedBlockHeader.getBlockheight());
|
|
311
|
+
if(BigInt(chainCommitment)!==BigInt(commitHash)) return null;
|
|
312
|
+
} catch (e: any) {
|
|
313
|
+
if(e.baseError?.code===40 && e.baseError?.revert_error!=null) return null;
|
|
314
|
+
throw e;
|
|
315
|
+
}
|
|
306
316
|
|
|
307
317
|
logger.debug("retrieveLogByCommitHash(): block found," +
|
|
308
318
|
" commit hash: "+commitmentHash+" blockhash: "+blockData.blockhash+" height: "+storedBlockHeader.getBlockheight());
|
|
@@ -327,8 +337,11 @@ export class StarknetBtcRelay<B extends BtcBlock>
|
|
|
327
337
|
const commitHash = event.params.commit_hash;
|
|
328
338
|
|
|
329
339
|
const [isInBtcMainChain, btcRelayCommitHash] = await Promise.all([
|
|
330
|
-
this._bitcoinRpc.isInMainChain(blockHashHex)
|
|
331
|
-
this.contract.get_commit_hash(storedHeader.getBlockheight())
|
|
340
|
+
this._bitcoinRpc.isInMainChain(blockHashHex),
|
|
341
|
+
this.contract.get_commit_hash(storedHeader.getBlockheight()).catch(e => {
|
|
342
|
+
if(e.baseError?.code===40 && e.baseError?.revert_error!=null) return 0n;
|
|
343
|
+
throw e;
|
|
344
|
+
})
|
|
332
345
|
]);
|
|
333
346
|
|
|
334
347
|
if(!isInBtcMainChain) return null;
|