Skip to content

Commit

Permalink
patches dev chain reset bug
Browse files Browse the repository at this point in the history
Bug referenced in #65. Will ignore web3 bug, which arises from expected block hash not exisitng, which can occur in dev environments, using ganache which can rapidly switch between various blockchain snapshots.
  • Loading branch information
D-Nice committed Dec 31, 2018
1 parent b014ca9 commit be4fc8e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions bridge.js
Expand Up @@ -81,6 +81,7 @@ var cliOptions = {
BridgeCliParse(cliOptions)

var cliConfiguration = BridgeCliParse().getConfiguration()
BridgeLogManager.passCliConf(cliConfiguration)

console.log('Please wait...')

Expand Down
15 changes: 14 additions & 1 deletion lib/bridge-log-manager.js
Expand Up @@ -14,6 +14,7 @@ const LogEmitter = new EventEmitter()
LogEmitter.setMaxListeners(1)

var logsContainer = []
var cliConfiguration

function BridgeLogManager () {
this.contractInstance = OracleInstance().getContractInstance()
Expand Down Expand Up @@ -127,7 +128,14 @@ const parseLog = function (err, log) {

if (logArgs['gasPrice']) logObj['parsed_log'].gasPrice = logArgs['gasPrice'].toNumber()

logObj['block_timestamp'] = BlockchainInterface().inter.getBlock(log['blockHash']).timestamp
try {
logObj['block_timestamp'] = BlockchainInterface().inter.getBlock(log['blockHash']).timestamp
} catch (e) {
// exception for dev chain resets (ganache)
if (e.message === 'Key not found in database' &&
cliConfiguration.dev === true) return
else throw e
}

emitsNewLog(null, logObj)
}
Expand All @@ -146,6 +154,10 @@ const removeAllLogs = function (e, type) {
} else process.exit()
}

const passCliConf = function (cliConf) {
cliConfiguration = cliConf
}

process.on('SIGINT', function () {
removeAllLogs(null, {'clean': true})
})
Expand All @@ -155,3 +167,4 @@ process.on('uncaughtException', removeAllLogs)
module.exports.init = singleton(BridgeLogManager)
module.exports.events = LogEmitter
module.exports.removeAllLogs = removeAllLogs
module.exports.passCliConf = passCliConf

0 comments on commit be4fc8e

Please sign in to comment.