Skip to content

Commit

Permalink
Merge pull request #40 from poanetwork/improve-logs
Browse files Browse the repository at this point in the history
Improve error messages
  • Loading branch information
rstormsf committed Jul 2, 2018
2 parents 2a00eee + fd5c1b8 commit 76a5d8f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ async function main({ msg, ackMsg, nackMsg, sendToQueue }) {
nonce++
console.log(`Tx generated ${txHash} for event Tx ${job.transactionReference}`)
} catch (e) {
console.error(e)
console.error(e.message)
console.error(`Tx Failed for event Tx ${job.transactionReference}`)
failedTx.push(job)

Expand Down
2 changes: 1 addition & 1 deletion src/services/gasPrice.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ async function getGasPrices() {
const json = await response.json()
return json[GAS_PRICE_SPEED_TYPE]
} catch (e) {
console.error('Gas Price API is not available', e)
console.error(`Gas Price API is not available. ${e.message}`)
return GAS_PRICE_FALLBACK
}
}
Expand Down
34 changes: 27 additions & 7 deletions src/tx/web3.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
// eslint-disable-next-line consistent-return
async function getNonce(web3, address) {
return web3.eth.getTransactionCount(address)
try {
return await web3.eth.getTransactionCount(address)
} catch (e) {
throw new Error(`Nonce cannot be obtained`)
}
}

function getBlockNumber(web3) {
return web3.eth.getBlockNumber()
async function getBlockNumber(web3) {
try {
return await web3.eth.getBlockNumber()
} catch (e) {
throw new Error(`Block Number cannot be obtained`)
}
}

async function getChainId(web3) {
Expand All @@ -15,13 +22,26 @@ async function getChainId(web3) {
}
}

function getRequiredBlockConfirmations(contract) {
return contract.methods.requiredBlockConfirmations().call()
async function getRequiredBlockConfirmations(contract) {
try {
return await contract.methods.requiredBlockConfirmations().call()
} catch (e) {
throw new Error(`Required block confirmations cannot be obtained`)
}
}

async function getEvents({ contract, event, fromBlock, toBlock }) {
try {
return await contract.getPastEvents(event, { fromBlock, toBlock })
} catch (e) {
throw new Error(`${event} events cannot be obtained`)
}
}

module.exports = {
getNonce,
getBlockNumber,
getChainId,
getRequiredBlockConfirmations
getRequiredBlockConfirmations,
getEvents
}
6 changes: 4 additions & 2 deletions src/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const processDeposits = require('./events/processDeposits')
const processCollectedSignatures = require('./events/processCollectedSignatures')
const processWithdraw = require('./events/processWithdraw')
const { redis } = require('./services/redisClient')
const { getRequiredBlockConfirmations } = require('./tx/web3')
const { getRequiredBlockConfirmations, getEvents } = require('./tx/web3')
const { checkHTTPS } = require('./utils/utils')

if (process.argv.length < 3) {
Expand Down Expand Up @@ -95,7 +95,9 @@ async function main({ sendToQueue }) {
if (lastBlockToProcess <= lastProcessedBlock) {
return
}
const events = await bridgeContract.getPastEvents(config.event, {
const events = await getEvents({
contract: bridgeContract,
event: config.event,
fromBlock: lastProcessedBlock + 1,
toBlock: lastBlockToProcess
})
Expand Down

0 comments on commit 76a5d8f

Please sign in to comment.