Add handling of error case with RPC links in getTokensState (#252)
* add handling for error case and extend logging
This commit is contained in:
parent
7054ff26a0
commit
9f9638970a
@ -8,6 +8,11 @@ const {
|
||||
getTokenType
|
||||
} = require('../../commons')
|
||||
|
||||
const emptyLogger = {
|
||||
debug: () => {},
|
||||
info: () => {}
|
||||
}
|
||||
|
||||
async function initialChecks() {
|
||||
const { ORACLE_BRIDGE_MODE, COMMON_FOREIGN_RPC_URL, COMMON_FOREIGN_BRIDGE_ADDRESS } = process.env
|
||||
let result = {}
|
||||
@ -18,7 +23,7 @@ async function initialChecks() {
|
||||
result.bridgeableTokenAddress = await bridge.methods.erc20token().call()
|
||||
} else if (ORACLE_BRIDGE_MODE === 'ERC_TO_NATIVE') {
|
||||
const bridge = new foreignWeb3.eth.Contract(FOREIGN_ERC_TO_NATIVE_ABI, COMMON_FOREIGN_BRIDGE_ADDRESS)
|
||||
result = await getTokensState(bridge)
|
||||
result = await getTokensState(bridge, emptyLogger)
|
||||
}
|
||||
|
||||
if (ORACLE_BRIDGE_MODE === 'ERC_TO_ERC') {
|
||||
|
@ -1,14 +1,25 @@
|
||||
async function getTokensState(bridgeContract) {
|
||||
async function getTokensState(bridgeContract, logger) {
|
||||
const context = {}
|
||||
context.bridgeableTokenAddress = await bridgeContract.methods.erc20token().call()
|
||||
try {
|
||||
logger.debug('Getting bridgeable token address')
|
||||
context.bridgeableTokenAddress = await bridgeContract.methods.erc20token().call()
|
||||
logger.debug({ address: context.bridgeableTokenAddress }, 'Token address obtained')
|
||||
} catch (e) {
|
||||
throw new Error(`Bridgeable token address cannot be obtained`)
|
||||
}
|
||||
|
||||
try {
|
||||
logger.debug('Getting Half Duplex token address')
|
||||
const halfDuplexErc20tokenAddress = await bridgeContract.methods.halfDuplexErc20token().call()
|
||||
logger.debug({ address: halfDuplexErc20tokenAddress }, 'Half Duplex token address obtained')
|
||||
if (halfDuplexErc20tokenAddress !== context.bridgeableTokenAddress) {
|
||||
context.halfDuplexTokenAddress = halfDuplexErc20tokenAddress
|
||||
} else {
|
||||
logger.info('Migration to support two tokens was not applied')
|
||||
context.idle = true
|
||||
}
|
||||
} catch (e) {
|
||||
logger.info('Old version of contracts is used')
|
||||
context.idle = true
|
||||
}
|
||||
|
||||
|
@ -125,11 +125,13 @@ async function checkConditions() {
|
||||
let state
|
||||
switch (config.id) {
|
||||
case 'erc-native-transfer':
|
||||
state = await getTokensState(bridgeContract)
|
||||
logger.debug('Getting token address to listen Transfer events')
|
||||
state = await getTokensState(bridgeContract, logger)
|
||||
updateEventContract(state.bridgeableTokenAddress)
|
||||
break
|
||||
case 'erc-native-half-duplex-transfer':
|
||||
state = await getTokensState(bridgeContract)
|
||||
logger.debug('Getting Half Duplex token address to listen Transfer events')
|
||||
state = await getTokensState(bridgeContract, logger)
|
||||
skipEvents = state.idle
|
||||
updateEventContract(state.halfDuplexTokenAddress)
|
||||
break
|
||||
|
Loading…
Reference in New Issue
Block a user