2019-06-07 14:19:12 +03:00
|
|
|
require('../env')
|
2019-05-06 14:12:53 +03:00
|
|
|
const Web3 = require('web3')
|
|
|
|
|
2019-07-12 15:37:41 +03:00
|
|
|
const { BRIDGE_VALIDATORS_ABI } = require('../../commons')
|
2019-05-06 14:12:53 +03:00
|
|
|
const rpcUrlsManager = require('../src/services/getRpcUrlsManager')
|
|
|
|
const { bridgeConfig } = require('../config/base.config')
|
|
|
|
|
|
|
|
const homeABI = bridgeConfig.homeBridgeAbi
|
|
|
|
const foreignABI = bridgeConfig.foreignBridgeAbi
|
|
|
|
|
|
|
|
async function getStartBlock(rpcUrl, bridgeAddress, bridgeAbi) {
|
|
|
|
try {
|
|
|
|
const web3Provider = new Web3.providers.HttpProvider(rpcUrl)
|
|
|
|
const web3Instance = new Web3(web3Provider)
|
|
|
|
const bridgeContract = new web3Instance.eth.Contract(bridgeAbi, bridgeAddress)
|
|
|
|
|
|
|
|
const deployedAtBlock = await bridgeContract.methods.deployedAtBlock().call()
|
|
|
|
|
|
|
|
const validatorContractAddress = await bridgeContract.methods.validatorContract().call()
|
2019-08-01 16:10:22 +03:00
|
|
|
const validatorContract = new web3Instance.eth.Contract(BRIDGE_VALIDATORS_ABI, validatorContractAddress)
|
2019-05-06 14:12:53 +03:00
|
|
|
|
|
|
|
const validatorDeployedAtBlock = await validatorContract.methods.deployedAtBlock().call()
|
|
|
|
|
|
|
|
const validatorAddedEvents = await validatorContract.getPastEvents('ValidatorAdded', {
|
|
|
|
fromBlock: validatorDeployedAtBlock,
|
2019-09-13 10:11:38 +03:00
|
|
|
filter: { validator: process.env.ORACLE_VALIDATOR_ADDRESS }
|
2019-05-06 14:12:53 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
return validatorAddedEvents.length ? validatorAddedEvents[0].blockNumber : deployedAtBlock
|
|
|
|
} catch (e) {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function main() {
|
2019-09-13 10:11:38 +03:00
|
|
|
const { COMMON_HOME_BRIDGE_ADDRESS, COMMON_FOREIGN_BRIDGE_ADDRESS } = process.env
|
2019-05-06 14:12:53 +03:00
|
|
|
|
|
|
|
const homeRpcUrl = rpcUrlsManager.homeUrls[0]
|
|
|
|
const foreignRpcUrl = rpcUrlsManager.foreignUrls[0]
|
2019-09-13 10:11:38 +03:00
|
|
|
const homeStartBlock = await getStartBlock(homeRpcUrl, COMMON_HOME_BRIDGE_ADDRESS, homeABI)
|
|
|
|
const foreignStartBlock = await getStartBlock(foreignRpcUrl, COMMON_FOREIGN_BRIDGE_ADDRESS, foreignABI)
|
2019-05-06 14:12:53 +03:00
|
|
|
const result = {
|
|
|
|
homeStartBlock,
|
|
|
|
foreignStartBlock
|
|
|
|
}
|
|
|
|
console.log(JSON.stringify(result))
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
main()
|
|
|
|
|
|
|
|
module.exports = main
|