Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// contracts (eg. storage contracts, discovery service contract, should not be allowed
// to relay TXes from here but can today).
const existingTx = await models.Transaction.findOne({
where: {
encodedABI: encodedABI // this should always be unique because of the nonce / sig
}
})
// if this transaction has already been submitted before and succeeded, send this receipt
if (existingTx) {
return existingTx.receipt
}
const contractName = contractRegistryKey.charAt(0).toUpperCase() + contractRegistryKey.slice(1) // uppercase the first letter
const decodedABI = AudiusABIDecoder.decodeMethod(contractName, encodedABI)
const privateKeyBuffer = Buffer.from(config.get('relayerPrivateKey'), 'hex')
const wallet = EthereumWallet.fromPrivateKey(privateKeyBuffer)
const address = wallet.getAddressString()
if (address !== config.get('relayerPublicKey').toLowerCase()) {
throw new Error('Invalid relayerPublicKey')
}
let gasPrice = parseInt(await web3.eth.getGasPrice())
if (isNaN(gasPrice) || gasPrice > HIGH_GAS_PRICE) {
gasPrice = GANACHE_GAS_PRICE
} else if (gasPrice === 0) {
// If the gas is zero, the txn will likely never get mined.
gasPrice = MIN_GAS_PRICE
} else if (gasPrice < MIN_GAS_PRICE) {
gasPrice = MIN_GAS_PRICE