Skip to content

Commit

Permalink
Update bridge transaction parser version
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanieliov committed May 27, 2024
1 parent db54939 commit a83cacc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 23 deletions.
20 changes: 14 additions & 6 deletions lib/rsk-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const expect = require('chai').expect;
const { getBridgeState } = require('@rsksmart/bridge-state-data-parser');
const { getBridge, getLatestActiveForkName } = require('./precompiled-abi-forks-util');
const hopBridgeTxParser = require('bridge-transaction-parser-hop400');
const fingerrootBridgeTxParser = require('bridge-transaction-parser-fingerroot500');
const BridgeTransactionParser = require('bridge-transaction-parser-lovell700');
const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider');
const { wait, retryWithCheck, removePrefix0x } = require('./utils');
const { waitForBitcoinMempoolToGetTxs } = require('./btc-utils');
Expand Down Expand Up @@ -49,7 +49,7 @@ const waitForSync = async (rskTransactionHelpers) => {
* @param {Number} maxAttempts defaults to 80 attempts by block.
* @returns {Promise<Number>} the latest block number the same or greater than `blockNumber`.
*/
const waitForBlock = (rskClient, blockNumber, waitTime = 250, maxAttempts = 160) => {
const waitForBlock = (rskClient, blockNumber, waitTime = 550, maxAttempts = 360) => {
return new Promise((resolve, reject) => {
let attempts = 1;
let latestBlockNumber = -1;
Expand Down Expand Up @@ -374,12 +374,9 @@ const findEventInBlock = async (rskTxHelper, eventName, fromBlockHashOrBlockNumb
if(fromBlockHashOrBlockNumber > toBlockHashOrBlockNumber) {
throw new Error(`fromBlockHashOrBlockNumber: ${fromBlockHashOrBlockNumber} is greater than toBlockHashOrBlockNumber: ${toBlockHashOrBlockNumber}`);
}

const isFingerroot500AlreadyActive = await Runners.common.forks.fingerroot500.isAlreadyActive();
const bridgeTxParser = isFingerroot500AlreadyActive ? fingerrootBridgeTxParser : hopBridgeTxParser;

while(fromBlockHashOrBlockNumber <= toBlockHashOrBlockNumber) {
const bridgeTransactions = await bridgeTxParser.getBridgeTransactionsInThisBlock(rskTxHelper.getClient(), fromBlockHashOrBlockNumber);
const bridgeTransactions = await findBridgeTransactionsInThisBlock(rskTxHelper.getClient(), fromBlockHashOrBlockNumber);
for(let i = 0; i < bridgeTransactions.length; i++) {
const tx = bridgeTransactions[i];
const event = tx.events.find(event => {
Expand All @@ -400,6 +397,17 @@ const findEventInBlock = async (rskTxHelper, eventName, fromBlockHashOrBlockNumb
return null;
};

const findBridgeTransactionsInThisBlock = async (web3Client, blockHashOrBlockNumber) => {
const isFingerroot500AlreadyActive = await Runners.common.forks.fingerroot500.isAlreadyActive();

if (isFingerroot500AlreadyActive) {
const bridgeTransactionParser = new BridgeTransactionParser(web3Client);
return bridgeTransactionParser.getBridgeTransactionsInThisBlock(blockHashOrBlockNumber);
} else {
return hopBridgeTxParser(web3Client, blockHashOrBlockNumber);
}
}

/**
* Imports the private key and unlocks the rskAddress, asserting that the rskAddress returned by the private key import is the same as the rskAddress provided.
* @param {RskTransactionHelper} rskTxHelper
Expand Down
34 changes: 18 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@rsksmart/pmt-builder": "^3.0.0",
"@rsksmart/powpeg-redeemscript-parser": "^1.0.0",
"bn.js": "^4.11.8",
"bridge-transaction-parser-fingerroot500": "github:rsksmart/bridge-transaction-parser#v0.5.0-beta",
"bridge-transaction-parser-lovell700": "git+https://github.com/rsksmart/bridge-transaction-parser#update-abis-version-to-lovell700",
"bridge-transaction-parser-hop400": "github:rsksmart/bridge-transaction-parser#v0.4.0-beta",
"btc-transaction-helper": "git+https://[email protected]/rsksmart/btc-transaction-helper#v3.5.0",
"chai": "^4.1.2",
Expand Down

0 comments on commit a83cacc

Please sign in to comment.