Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
require('dotenv').config({
path: path.join(__dirname, '..', '.env')
})
const { isAddress, toBN } = require('web3').utils
const envalid = require('envalid')
const { ZERO_ADDRESS, EVM_TYPES } = require('./constants')
const homePrefix = 'HOME'
const foreignPrefix = 'FOREIGN'
// Validations and constants
const evmVersions = [EVM_TYPES.BYZANTIUM, EVM_TYPES.SPURIOUSDRAGON]
const validBridgeModes = ['NATIVE_TO_ERC', 'ERC_TO_ERC', 'ERC_TO_NATIVE']
const validRewardModes = ['false', 'ONE_DIRECTION', 'BOTH_DIRECTIONS']
const validFeeManagerTypes = ['BRIDGE_VALIDATORS_REWARD', 'POSDAO_REWARD']
const bigNumValidator = envalid.makeValidator(x => toBN(x))
const validateAddress = address => {
if (isAddress(address)) {
return address
}
throw new Error(`Invalid address: ${address}`)
}
const addressValidator = envalid.makeValidator(validateAddress)
const addressesValidator = envalid.makeValidator(addresses => {
addresses.split(' ').forEach(validateAddress)
return addresses
})
const validateRewardableAddresses = (validators, rewards) => {
const validatorsLength = validators ? validators.split(' ').length : 0
const validatorsRewardLength = rewards ? rewards.split(' ').length : 0
if (validatorsLength !== validatorsRewardLength) {
const foreignPrefix = 'FOREIGN'
// Validations and constants
const evmVersions = [EVM_TYPES.BYZANTIUM, EVM_TYPES.SPURIOUSDRAGON]
const validBridgeModes = ['NATIVE_TO_ERC', 'ERC_TO_ERC', 'ERC_TO_NATIVE']
const validRewardModes = ['false', 'ONE_DIRECTION', 'BOTH_DIRECTIONS']
const validFeeManagerTypes = ['BRIDGE_VALIDATORS_REWARD', 'POSDAO_REWARD']
const bigNumValidator = envalid.makeValidator(x => toBN(x))
const validateAddress = address => {
if (isAddress(address)) {
return address
}
throw new Error(`Invalid address: ${address}`)
}
const addressValidator = envalid.makeValidator(validateAddress)
const addressesValidator = envalid.makeValidator(addresses => {
addresses.split(' ').forEach(validateAddress)
return addresses
})
const validateRewardableAddresses = (validators, rewards) => {
const validatorsLength = validators ? validators.split(' ').length : 0
const validatorsRewardLength = rewards ? rewards.split(' ').length : 0
if (validatorsLength !== validatorsRewardLength) {
throw new Error(
`List of rewards accounts (${validatorsRewardLength} accounts) should be the same length as list of validators (${validatorsLength} accounts)`
)
}
}
function checkValidators(validators, requiredValidators) {
if (validators.split(' ').length < requiredValidators) {
// Validations and constants
const evmVersions = [EVM_TYPES.BYZANTIUM, EVM_TYPES.SPURIOUSDRAGON]
const validBridgeModes = ['NATIVE_TO_ERC', 'ERC_TO_ERC', 'ERC_TO_NATIVE']
const validRewardModes = ['false', 'ONE_DIRECTION', 'BOTH_DIRECTIONS']
const validFeeManagerTypes = ['BRIDGE_VALIDATORS_REWARD', 'POSDAO_REWARD']
const bigNumValidator = envalid.makeValidator(x => toBN(x))
const validateAddress = address => {
if (isAddress(address)) {
return address
}
throw new Error(`Invalid address: ${address}`)
}
const addressValidator = envalid.makeValidator(validateAddress)
const addressesValidator = envalid.makeValidator(addresses => {
addresses.split(' ').forEach(validateAddress)
return addresses
})
const validateRewardableAddresses = (validators, rewards) => {
const validatorsLength = validators ? validators.split(' ').length : 0
const validatorsRewardLength = rewards ? rewards.split(' ').length : 0
if (validatorsLength !== validatorsRewardLength) {
throw new Error(
`List of rewards accounts (${validatorsRewardLength} accounts) should be the same length as list of validators (${validatorsLength} accounts)`
)
}
}
function checkValidators(validators, requiredValidators) {
if (validators.split(' ').length < requiredValidators) {
throw new Error(
import envalid, { bool, makeValidator, str } from "envalid";
const bodyParserValidator = makeValidator((value) => {
if (typeof value !== "number") throw new Error("Expected type number");
if (value <= 0) throw new Error("Expected value to be greater than 0");
return value;
});
export default envalid.cleanEnv(process.env, {
BODY_PARSER_SIZE_LIMIT: bodyParserValidator({
default: 5 * 1000000 // value in bytes = 5mb
}),
GRAPHQL_INTROSPECTION_ENABLED: bool({ default: false }),
GRAPHQL_PLAYGROUND_ENABLED: bool({ default: false }),
MIGRATION_BYPASS_ENABLED: bool({
default: false,
desc: "Bypasses migration version checks and migration runs. Enables startup if migration state is not compatible. " +
"This can be dangerous enough to cause data inconsistencies. Use at your own risk!"
}),