diff --git a/lib/rsk-utils.js b/lib/rsk-utils.js index a8644d02..6bf449a5 100644 --- a/lib/rsk-utils.js +++ b/lib/rsk-utils.js @@ -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'); @@ -49,7 +49,7 @@ const waitForSync = async (rskTransactionHelpers) => { * @param {Number} maxAttempts defaults to 80 attempts by block. * @returns {Promise} 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; @@ -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 => { @@ -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 diff --git a/package-lock.json b/package-lock.json index 065ae472..8c622ba1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,8 +15,8 @@ "@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-hop400": "github:rsksmart/bridge-transaction-parser#v0.4.0-beta", + "bridge-transaction-parser-lovell700": "git+https://github.com/rsksmart/bridge-transaction-parser#update-abis-version-to-lovell700", "btc-transaction-helper": "git+https://git@github.com/rsksmart/btc-transaction-helper#v3.5.0", "chai": "^4.1.2", "chai-as-promised": "^7.1.1", @@ -772,12 +772,6 @@ "resolved": "https://registry.npmjs.org/@rsksmart/rsk-precompiled-abis/-/rsk-precompiled-abis-6.0.0-ARROWHEAD.tgz", "integrity": "sha512-+g22mIXjdTHoakCXnjttA9MMJMVyYzZ8VsAL4bMPeTZ8kn9OCZBpXkAtCsXkDCGeYCgrWD9F3VS59vBb/AOdGA==" }, - "node_modules/@rsksmart/rsk-precompiled-abis-fingerroot500": { - "name": "@rsksmart/rsk-precompiled-abis", - "version": "5.0.0-FINGERROOT", - "resolved": "https://registry.npmjs.org/@rsksmart/rsk-precompiled-abis/-/rsk-precompiled-abis-5.0.0-FINGERROOT.tgz", - "integrity": "sha512-mKaKicuEzyLqQgnWZOBfyjdzMGjdGDqcGWkH4jXK7Edd8u62np0B7GUJLoXjHFDP6G28A/HqROx1tlGoJJcQ4Q==" - }, "node_modules/@rsksmart/rsk-precompiled-abis-hop400": { "name": "@rsksmart/rsk-precompiled-abis", "version": "5.0.0-HOP", @@ -1343,15 +1337,6 @@ "node": ">=8" } }, - "node_modules/bridge-transaction-parser-fingerroot500": { - "name": "bridge-transaction-parser", - "version": "0.5.0-beta", - "resolved": "git+ssh://git@github.com/rsksmart/bridge-transaction-parser.git#2f08c20dfdf471766bcc10faed01ece183b8f229", - "license": "MIT", - "dependencies": { - "@rsksmart/rsk-precompiled-abis-fingerroot500": "npm:@rsksmart/rsk-precompiled-abis@5.0.0-FINGERROOT" - } - }, "node_modules/bridge-transaction-parser-hop400": { "name": "bridge-transaction-parser", "version": "0.4.0-beta", @@ -1361,6 +1346,23 @@ "@rsksmart/rsk-precompiled-abis-hop400": "npm:@rsksmart/rsk-precompiled-abis@5.0.0-HOP" } }, + "node_modules/bridge-transaction-parser-lovell700": { + "name": "@rsksmart/bridge-transaction-parser", + "version": "1.1.2", + "resolved": "git+ssh://git@github.com/rsksmart/bridge-transaction-parser.git#62c846ddaabd45a45dbc3dfb8432358d4ac8a0db", + "license": "MIT", + "dependencies": { + "@rsksmart/rsk-precompiled-abis": "^5.0.0-FINGERROOT" + } + }, + "node_modules/bridge-transaction-parser-lovell700/node_modules/@rsksmart/rsk-precompiled-abis": { + "version": "5.0.0-HOP", + "resolved": "https://registry.npmjs.org/@rsksmart/rsk-precompiled-abis/-/rsk-precompiled-abis-5.0.0-HOP.tgz", + "integrity": "sha512-VCSQRNE+3qeyMUsEPTxHTbj1MxmJSVJaeBwrYZg7vN46KFE4FaZd9hYp8iNpOUmpyZNhXySdVSFV9wlcubR1Gw==", + "dependencies": { + "web3": "^1.3.6" + } + }, "node_modules/brorand": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/brorand/-/brorand-1.1.0.tgz", diff --git a/package.json b/package.json index a9d0c27a..62533164 100644 --- a/package.json +++ b/package.json @@ -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://git@github.com/rsksmart/btc-transaction-helper#v3.5.0", "chai": "^4.1.2",