2020-10-29 11:25:43 +03:00
|
|
|
require('dotenv').config()
|
|
|
|
const Web3 = require('web3')
|
|
|
|
|
|
|
|
const { COMMON_HOME_RPC_URL, COMMON_FOREIGN_RPC_URL } = process.env
|
|
|
|
|
|
|
|
const homeProvider = new Web3.providers.HttpProvider(COMMON_HOME_RPC_URL)
|
|
|
|
const web3Home = new Web3(homeProvider)
|
|
|
|
|
|
|
|
const foreignProvider = new Web3.providers.HttpProvider(COMMON_FOREIGN_RPC_URL)
|
|
|
|
const web3Foreign = new Web3(foreignProvider)
|
|
|
|
|
2020-11-04 14:24:42 +03:00
|
|
|
function blockNumberWrapper(web3) {
|
|
|
|
let blockNumber = null
|
|
|
|
return async () => {
|
|
|
|
if (!blockNumber) {
|
|
|
|
blockNumber = await web3.eth.getBlockNumber()
|
|
|
|
}
|
|
|
|
return blockNumber
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-29 11:25:43 +03:00
|
|
|
module.exports = {
|
|
|
|
web3Home,
|
2020-11-04 14:24:42 +03:00
|
|
|
web3Foreign,
|
|
|
|
getHomeBlockNumber: blockNumberWrapper(web3Home),
|
|
|
|
getForeignBlockNumber: blockNumberWrapper(web3Foreign)
|
2020-10-29 11:25:43 +03:00
|
|
|
}
|