2019-06-07 14:19:12 +03:00
|
|
|
require('../env')
|
2019-05-06 14:12:53 +03:00
|
|
|
|
2019-07-12 15:37:41 +03:00
|
|
|
const { BRIDGE_VALIDATORS_ABI } = require('../../commons')
|
2021-05-09 16:34:19 +03:00
|
|
|
const { home, foreign } = require('../config/base.config')
|
2019-05-06 14:12:53 +03:00
|
|
|
|
2021-05-09 16:34:19 +03:00
|
|
|
async function getStartBlock(bridgeContract, web3) {
|
2019-05-06 14:12:53 +03:00
|
|
|
try {
|
|
|
|
const deployedAtBlock = await bridgeContract.methods.deployedAtBlock().call()
|
|
|
|
|
|
|
|
const validatorContractAddress = await bridgeContract.methods.validatorContract().call()
|
2020-10-28 14:20:50 +03:00
|
|
|
const validatorContract = new web3.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() {
|
2021-05-09 16:34:19 +03:00
|
|
|
const homeStartBlock = await getStartBlock(home.bridgeContract, home.web3)
|
|
|
|
const foreignStartBlock = await getStartBlock(foreign.bridgeContract, foreign.web3)
|
2019-05-06 14:12:53 +03:00
|
|
|
const result = {
|
|
|
|
homeStartBlock,
|
|
|
|
foreignStartBlock
|
|
|
|
}
|
|
|
|
console.log(JSON.stringify(result))
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
main()
|
|
|
|
|
|
|
|
module.exports = main
|