Skip to content

Commit

Permalink
Update bridge transaction parser dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanieliov committed Jun 7, 2024
1 parent d7061fc commit 36dbb1e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
19 changes: 15 additions & 4 deletions lib/rsk-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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 @@ -374,12 +375,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 +398,19 @@ const findEventInBlock = async (rskTxHelper, eventName, fromBlockHashOrBlockNumb
return null;
};

const findBridgeTransactionsInThisBlock = async (web3Client, blockHashOrBlockNumber) => {
const isLovell700AlreadyActive = await Runners.common.forks.lovell700.isAlreadyActive()

if (isLovell700AlreadyActive){
const bridgeTransactionParser = new BridgeTransactionParser(web3Client);
return bridgeTransactionParser.getBridgeTransactionsInThisBlock(blockHashOrBlockNumber);
}

const isFingerroot500AlreadyActive = await Runners.common.forks.fingerroot500.isAlreadyActive();
const bridgeTxParser = isFingerroot500AlreadyActive ? fingerrootBridgeTxParser : hopBridgeTxParser;
return bridgeTxParser.getBridgeTransactionsInThisBlock(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
31 changes: 21 additions & 10 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@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 36dbb1e

Please sign in to comment.