Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes the federation from the start. #78

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const FEE_DIFFERENCE_PER_PEGOUT = 3200;
const NUMBER_OF_BLOCKS_BTW_PEGOUTS = 50;

const FEDERATION_ACTIVATION_AGE = 20;
const FUNDS_MIGRATION_AGE_SINCE_ACTIVATION_BEGIN = 15;
const FUNDS_MIGRATION_AGE_SINCE_ACTIVATION_END = 150;

const PEGIN_REJECTION_REASONS = {
PEGIN_CAP_SURPASSED_REASON: '1',
Expand Down Expand Up @@ -72,5 +74,7 @@ module.exports = {
GENESIS_FEDERATION_REDEEM_SCRIPT,
FEDERATION_ACTIVATION_AGE,
PEGIN_REJECTION_REASONS,
PEGOUT_EVENTS
PEGOUT_EVENTS,
FUNDS_MIGRATION_AGE_SINCE_ACTIVATION_BEGIN,
FUNDS_MIGRATION_AGE_SINCE_ACTIVATION_END,
};
8 changes: 4 additions & 4 deletions lib/rsk-utils.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
const expect = require('chai').expect;
const { getBridgeState } = require('@rsksmart/bridge-state-data-parser');
const { getBridge } = 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 BridgeTransactionParser = require('@rsksmart/bridge-transaction-parser');
const { getRskTransactionHelpers } = require('../lib/rsk-tx-helper-provider');
const { wait, retryWithCheck, removePrefix0x } = require('./utils');
const { waitForBitcoinMempoolToGetTxs } = require('./btc-utils');
Expand Down Expand Up @@ -414,11 +412,13 @@ const findEventInBlock = async (rskTxHelper, eventName, fromBlockHashOrBlockNumb

const findBridgeTransactionsInThisBlock = async (web3Client, blockHashOrBlockNumber) => {

const bridgeTxParser = new BridgeTransactionParser(web3Client);

// TODO: uncomment this when lovell700 is active.
// const bridgeTransactionParser = new BridgeTransactionParser(web3Client);
// return bridgeTransactionParser.getBridgeTransactionsInThisBlock(blockHashOrBlockNumber);

return fingerrootBridgeTxParser.getBridgeTransactionsInThisBlock(web3Client, blockHashOrBlockNumber);
return bridgeTxParser.getBridgeTransactionsInThisBlock(blockHashOrBlockNumber);
}

/**
Expand Down
30 changes: 28 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var getRandomInt = (min, max) => {

const ensure0x = (value) => value.substr(0, 2) == '0x' ? value : `0x${value}`;

const removePrefix0x = hash => hash.substr(2);
const removePrefix0x = hash => hash.startsWith('0x') ? hash.substring(2) : hash;;

const executeWithRetries = async(method, retries, delay) => {
for (let j = 0; j < retries; j++) {
Expand Down Expand Up @@ -135,6 +135,31 @@ const retryWithCheck = async (method, check, maxAttempts = 3, delayInMillisecond
};
};

/**
* Splits a given string into chunks of specified length.
*
* @param {string} inputString - The string to be split into smaller chunks.
* @param {number} chunkSize - The length of each chunk.
* @returns {string[]} An array of strings, each containing a segment of the input string,
* with a maximum length of `chunkSize`. If the input string's length
* is not divisible by `chunkSize`, the last chunk may be shorter.
*
* @example
* splitStringIntoChunks("Hello World!", 5);
* // returns ["Hello", " Worl", "d!"]
*
* @throws {Error} If chunkSize is less than 1 or not a number.
*/
function splitStringIntoChunks(inputString, chunkSize) {
if (!Number.isInteger(chunkSize) || chunkSize < 1) {
throw new Error('chunkSize must be a positive number.');
}

// Use the chunk size in the regular expression to match segments of the given length
const regex = new RegExp(`.{1,${chunkSize}}`, 'g');
return inputString.match(regex);
}

module.exports = {
sequentialPromise,
mapPromiseAll,
Expand All @@ -153,5 +178,6 @@ module.exports = {
get: getAdditionalFederationAddresses,
add: addAdditionalFederationAddress,
remove: removeAdditionalFederationAddress
}
},
splitStringIntoChunks,
}
Loading