Function naming (#208)

* Function naming

* More renames from oracle to gas supplier
This commit is contained in:
Przemyslaw Rzad 2019-09-13 14:54:51 +02:00 committed by GitHub
parent 114f62da7b
commit 6b55c54497
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 26 deletions

@ -203,7 +203,7 @@ const normalizeGasPrice = (oracleGasPrice, factor, limits = null) => {
// fetchFn has to be supplied (instead of just url to oracle),
// because this utility function is shared between Browser and Node,
// we use built-in 'fetch' on browser side, and `node-fetch` package in Node.
const gasPriceFromOracle = async (fetchFn, options = {}) => {
const gasPriceFromSupplier = async (fetchFn, options = {}) => {
try {
const response = await fetchFn()
const json = await response.json()
@ -256,7 +256,7 @@ module.exports = {
getPastEvents,
getDeployedAtBlock,
normalizeGasPrice,
gasPriceFromOracle,
gasPriceFromSupplier,
gasPriceFromContract,
gasPriceWithinLimits
}

@ -2,7 +2,7 @@ require('dotenv').config()
const Web3 = require('web3')
const fetch = require('node-fetch')
const logger = require('./logger')('validators')
const { getBridgeABIs, BRIDGE_VALIDATORS_ABI, getValidatorList, gasPriceFromOracle } = require('../commons')
const { getBridgeABIs, BRIDGE_VALIDATORS_ABI, getValidatorList, gasPriceFromSupplier } = require('../commons')
const { getBlockNumber } = require('./utils/contract')
const {
@ -32,13 +32,13 @@ const web3Home = new Web3(homeProvider)
const foreignProvider = new Web3.providers.HttpProvider(COMMON_FOREIGN_RPC_URL)
const web3Foreign = new Web3(foreignProvider)
const homeGasOracleOpts = {
const homeGasPriceSupplierOpts = {
speedType: COMMON_HOME_GAS_PRICE_SPEED_TYPE,
factor: COMMON_HOME_GAS_PRICE_FACTOR,
logger
}
const foreignGasOracleOpts = {
const foreignGasPriceSupplierOpts = {
speedType: COMMON_FOREIGN_GAS_PRICE_SPEED_TYPE,
factor: COMMON_FOREIGN_GAS_PRICE_FACTOR,
logger
@ -88,14 +88,14 @@ async function main(bridgeMode) {
logger.debug('calling home getGasPrices')
const homeGasPrice =
(await gasPriceFromOracle(() => fetch(COMMON_HOME_GAS_PRICE_SUPPLIER_URL), homeGasOracleOpts)) ||
(await gasPriceFromSupplier(() => fetch(COMMON_HOME_GAS_PRICE_SUPPLIER_URL), homeGasPriceSupplierOpts)) ||
Web3Utils.toBN(COMMON_HOME_GAS_PRICE_FALLBACK)
const homeGasPriceGwei = Web3Utils.fromWei(homeGasPrice.toString(), 'gwei')
const homeTxCost = homeGasPrice.mul(Web3Utils.toBN(MONITOR_VALIDATOR_HOME_TX_LIMIT))
logger.debug('calling foreign getGasPrices')
const foreignGasPrice =
(await gasPriceFromOracle(() => fetch(COMMON_FOREIGN_GAS_PRICE_SUPPLIER_URL), foreignGasOracleOpts)) ||
(await gasPriceFromSupplier(() => fetch(COMMON_FOREIGN_GAS_PRICE_SUPPLIER_URL), foreignGasPriceSupplierOpts)) ||
Web3Utils.toBN(COMMON_FOREIGN_GAS_PRICE_FALLBACK)
const foreignGasPriceGwei = Web3Utils.fromWei(foreignGasPrice.toString(), 'gwei')
const foreignTxCost = foreignGasPrice.mul(Web3Utils.toBN(MONITOR_VALIDATOR_FOREIGN_TX_LIMIT))

@ -7,7 +7,7 @@ const logger = require('../services/logger').child({
})
const { setIntervalAndRun } = require('../utils/utils')
const { DEFAULT_UPDATE_INTERVAL, GAS_PRICE_BOUNDARIES, DEFAULT_GAS_PRICE_FACTOR } = require('../utils/constants')
const { gasPriceFromOracle, gasPriceFromContract } = require('../../../commons')
const { gasPriceFromSupplier, gasPriceFromContract } = require('../../../commons')
const HomeABI = bridgeConfig.homeBridgeAbi
const ForeignABI = bridgeConfig.foreignBridgeAbi
@ -35,11 +35,11 @@ let cachedGasPrice = null
let fetchGasPriceInterval = null
const fetchGasPrice = async (speedType, factor, bridgeContract, oracleFetchFn) => {
const fetchGasPrice = async (speedType, factor, bridgeContract, gasPriceSupplierFetchFn) => {
const contractOptions = { logger }
const oracleOptions = { speedType, factor, limits: GAS_PRICE_BOUNDARIES, logger }
const supplierOptions = { speedType, factor, limits: GAS_PRICE_BOUNDARIES, logger }
cachedGasPrice =
(await gasPriceFromOracle(oracleFetchFn, oracleOptions)) ||
(await gasPriceFromSupplier(gasPriceSupplierFetchFn, supplierOptions)) ||
(await gasPriceFromContract(bridgeContract, contractOptions)) ||
cachedGasPrice
return cachedGasPrice
@ -49,13 +49,13 @@ async function start(chainId) {
clearInterval(fetchGasPriceInterval)
let bridgeContract = null
let oracleUrl = null
let gasPriceSupplierUrl = null
let speedType = null
let updateInterval = null
let factor = null
if (chainId === 'home') {
bridgeContract = homeBridge
oracleUrl = COMMON_HOME_GAS_PRICE_SUPPLIER_URL
gasPriceSupplierUrl = COMMON_HOME_GAS_PRICE_SUPPLIER_URL
speedType = COMMON_HOME_GAS_PRICE_SPEED_TYPE
updateInterval = ORACLE_HOME_GAS_PRICE_UPDATE_INTERVAL || DEFAULT_UPDATE_INTERVAL
factor = Number(COMMON_HOME_GAS_PRICE_FACTOR) || DEFAULT_GAS_PRICE_FACTOR
@ -63,7 +63,7 @@ async function start(chainId) {
cachedGasPrice = COMMON_HOME_GAS_PRICE_FALLBACK
} else if (chainId === 'foreign') {
bridgeContract = foreignBridge
oracleUrl = COMMON_FOREIGN_GAS_PRICE_SUPPLIER_URL
gasPriceSupplierUrl = COMMON_FOREIGN_GAS_PRICE_SUPPLIER_URL
speedType = COMMON_FOREIGN_GAS_PRICE_SPEED_TYPE
updateInterval = ORACLE_FOREIGN_GAS_PRICE_UPDATE_INTERVAL || DEFAULT_UPDATE_INTERVAL
factor = Number(COMMON_FOREIGN_GAS_PRICE_FACTOR) || DEFAULT_GAS_PRICE_FACTOR
@ -74,7 +74,7 @@ async function start(chainId) {
}
fetchGasPriceInterval = setIntervalAndRun(
() => fetchGasPrice(speedType, factor, bridgeContract, () => fetch(oracleUrl)),
() => fetchGasPrice(speedType, factor, bridgeContract, () => fetch(gasPriceSupplierUrl)),
updateInterval
)
}

@ -66,7 +66,7 @@ describe('gasPrice', () => {
describe('fetching gas price', () => {
const utils = { setIntervalAndRun: () => {} }
it('should fall back to default if contract and oracle/supplier are not working', async () => {
it('should fall back to default if contract and supplier are not working', async () => {
// given
process.env.COMMON_HOME_GAS_PRICE_FALLBACK = '101000000000'
const gasPrice = proxyquire('../src/services/gasPrice', { '../utils/utils': utils })
@ -79,20 +79,20 @@ describe('gasPrice', () => {
expect(gasPrice.getPrice()).to.equal('101000000000')
})
it('should fetch gas from oracle/supplier', async () => {
it('should fetch gas from supplier', async () => {
// given
process.env.COMMON_HOME_GAS_PRICE_FALLBACK = '101000000000'
const gasPrice = proxyquire('../src/services/gasPrice', { '../utils/utils': utils })
await gasPrice.start('home')
const oracleFetchFn = () => ({
const gasPriceSupplierFetchFn = () => ({
json: () => ({
standard: '103'
})
})
// when
await gasPrice.fetchGasPrice('standard', 1, null, oracleFetchFn)
await gasPrice.fetchGasPrice('standard', 1, null, gasPriceSupplierFetchFn)
// then
expect(gasPrice.getPrice().toString()).to.equal('103000000000')
@ -133,14 +133,14 @@ describe('gasPrice', () => {
}
}
const oracleFetchFn = () => ({
const gasPriceSupplierFetchFn = () => ({
json: () => ({
standard: '103'
})
})
// when
await gasPrice.fetchGasPrice('standard', 1, bridgeContractMock, oracleFetchFn)
await gasPrice.fetchGasPrice('standard', 1, bridgeContractMock, gasPriceSupplierFetchFn)
// then
expect(gasPrice.getPrice().toString()).to.equal('103000000000')

@ -1,6 +1,6 @@
import { observable, computed } from 'mobx'
import { toHex } from 'web3-utils'
import { gasPriceFromOracle } from '../../../commons'
import { gasPriceFromSupplier } from '../../../commons'
const {
REACT_APP_COMMON_HOME_GAS_PRICE_FALLBACK,
@ -21,7 +21,7 @@ const DEFAULT_GAS_PRICE_UPDATE_INTERVAL = 900000
class GasPriceStore {
@observable
gasPrice = null
oracleUrl = null
gasPriceSupplierUrl = null
speedType = null
updateInterval = null
factor = null
@ -40,20 +40,20 @@ class GasPriceStore {
if (await this.web3Store.onHomeSide()) {
this.gasPrice = REACT_APP_COMMON_HOME_GAS_PRICE_FALLBACK
this.oracleUrl = REACT_APP_COMMON_HOME_GAS_PRICE_SUPPLIER_URL
this.gasPriceSupplierUrl = REACT_APP_COMMON_HOME_GAS_PRICE_SUPPLIER_URL
this.speedType = REACT_APP_COMMON_HOME_GAS_PRICE_SPEED_TYPE
this.updateInterval = REACT_APP_UI_HOME_GAS_PRICE_UPDATE_INTERVAL || DEFAULT_GAS_PRICE_UPDATE_INTERVAL
this.factor = Number(REACT_APP_COMMON_HOME_GAS_PRICE_FACTOR) || DEFAULT_GAS_PRICE_FACTOR
} else {
this.gasPrice = REACT_APP_COMMON_FOREIGN_GAS_PRICE_FALLBACK
this.oracleUrl = REACT_APP_COMMON_FOREIGN_GAS_PRICE_SUPPLIER_URL
this.gasPriceSupplierUrl = REACT_APP_COMMON_FOREIGN_GAS_PRICE_SUPPLIER_URL
this.speedType = REACT_APP_COMMON_FOREIGN_GAS_PRICE_SPEED_TYPE
this.updateInterval = REACT_APP_UI_FOREIGN_GAS_PRICE_UPDATE_INTERVAL || DEFAULT_GAS_PRICE_UPDATE_INTERVAL
this.factor = Number(REACT_APP_COMMON_FOREIGN_GAS_PRICE_FACTOR) || DEFAULT_GAS_PRICE_FACTOR
}
const oracleOptions = { speedType: this.speedType, factor: this.factor, logger: console }
this.gasPrice = (await gasPriceFromOracle(() => fetch(this.oracleUrl), oracleOptions)) || this.gasPrice
this.gasPrice = (await gasPriceFromSupplier(() => fetch(this.gasPriceSupplierUrl), oracleOptions)) || this.gasPrice
setTimeout(() => this.updateGasPrice(), this.updateInterval)
}