Skip to content

Commit

Permalink
add useCommit arg
Browse files Browse the repository at this point in the history
  • Loading branch information
zkbenny committed May 10, 2024
1 parent e696ec4 commit ac8d0e2
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions examples/zklinkNova/scripts/getTxStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ require('dotenv').config();

task('getTxStatus', 'Get the tx status of nova')
.addParam('txHash', 'The tx hash', undefined, types.string)
.addOptionalParam('useCommit', 'Use commit as the nova finalize tx', true, types.boolean)
.setAction(async taskArgs => {
const txHash = taskArgs.txHash;
const useCommit = taskArgs.useCommit;
console.log(`Get the status of tx: ${txHash}`);
const zkLinkNovaProvider = new Provider(process.env.ZKLINK_NOVA_RPC);
const lineaProvider = new ethers.JsonRpcProvider(process.env.LINEA_RPC);
Expand All @@ -23,18 +25,19 @@ task('getTxStatus', 'Get the tx status of nova')
console.log(`Tx block: ${txReceipt.blockNumber}`);

const blockDetails = await zkLinkNovaProvider.getBlockDetails(txReceipt.blockNumber);
if (!blockDetails.proveTxHash) {
console.log(`Tx status: not proved`);
const novaFinalizeTx = useCommit ? blockDetails.commitTxHash : blockDetails.proveTxHash;
if (!novaFinalizeTx) {
console.log(`Tx status: not finalized on linea`);
return;
}
console.log(`Block prove tx hash: ${blockDetails.commitTxHash}`);
console.log(`Nova finalize tx hash: ${novaFinalizeTx}`);

const blockCommitTxReceipt = await lineaProvider.getTransactionReceipt(blockDetails.commitTxHash);
if (!blockCommitTxReceipt.blockNumber) {
console.log(`Tx status: prove tx not confirmed`);
const novaFinalizeTxReceipt = await lineaProvider.getTransactionReceipt(novaFinalizeTx);
if (!novaFinalizeTxReceipt.blockNumber) {
console.log(`Tx status: nova finalize tx not confirmed`);
return;
}
console.log(`Prove tx block number on linea: ${blockCommitTxReceipt.blockNumber}`);
console.log(`Nova finalize tx block number on linea: ${novaFinalizeTxReceipt.blockNumber}`);

const ethereumChainId = (await ethereumProvider.getNetwork()).chainId;
const network = ethereumChainId === BigInt(1) ? 'linea-mainnet' : 'linea-sepolia';
Expand All @@ -49,9 +52,9 @@ task('getTxStatus', 'Get the tx status of nova')
const lineaRollup = LineaRollup__factory.connect(lineaL1Contract.contractAddress, ethereumProvider);
const currentFinalizeBlockNumber = await lineaRollup.currentL2BlockNumber();
console.log(`Linea current finalize block number: ${currentFinalizeBlockNumber}`);
if (currentFinalizeBlockNumber >= blockCommitTxReceipt.blockNumber) {
console.log(`Tx status: finalized`);
if (currentFinalizeBlockNumber >= novaFinalizeTxReceipt.blockNumber) {
console.log(`Tx status: finalized on ethereum`);
} else {
console.log(`Tx status: not finalized`);
console.log(`Tx status: not finalized on ethereum`);
}
});

0 comments on commit ac8d0e2

Please sign in to comment.