tokenbridge/monitor/eventsStats.js

78 lines
2.7 KiB
JavaScript
Raw Normal View History

2019-05-08 16:12:02 +03:00
require('dotenv').config()
const eventsInfo = require('./utils/events')
const {
processedMsgNotDelivered,
deliveredMsgNotProcessed,
eventWithoutReference,
unclaimedHomeToForeignRequests
} = require('./utils/message')
const { getHomeTxSender } = require('./utils/web3Cache')
2019-09-18 22:45:13 +03:00
const { BRIDGE_MODES } = require('../commons')
2019-05-08 16:12:02 +03:00
const {
MONITOR_HOME_TO_FOREIGN_ALLOWANCE_LIST,
MONITOR_HOME_TO_FOREIGN_BLOCK_LIST,
MONITOR_HOME_TO_FOREIGN_CHECK_SENDER
} = process.env
2019-05-08 16:12:02 +03:00
async function main() {
2019-09-18 22:45:13 +03:00
const {
homeToForeignRequests,
homeToForeignConfirmations,
foreignToHomeConfirmations,
foreignToHomeRequests,
bridgeMode
} = await eventsInfo()
2019-05-08 16:12:02 +03:00
2019-09-18 22:45:13 +03:00
if (bridgeMode === BRIDGE_MODES.ARBITRARY_MESSAGE) {
return {
home: {
deliveredMsgNotProcessedInForeign: homeToForeignRequests.filter(
deliveredMsgNotProcessed(homeToForeignConfirmations)
),
processedMsgNotDeliveredInForeign: foreignToHomeConfirmations.filter(
processedMsgNotDelivered(foreignToHomeRequests)
)
},
foreign: {
deliveredMsgNotProcessedInHome: foreignToHomeRequests.filter(
deliveredMsgNotProcessed(foreignToHomeConfirmations)
),
processedMsgNotDeliveredInHome: homeToForeignConfirmations.filter(
processedMsgNotDelivered(homeToForeignRequests)
)
},
lastChecked: Math.floor(Date.now() / 1000)
}
} else {
let onlyInHomeDeposits = homeToForeignRequests.filter(eventWithoutReference(homeToForeignConfirmations))
const onlyInForeignDeposits = homeToForeignConfirmations.filter(eventWithoutReference(homeToForeignRequests))
2019-05-08 16:12:02 +03:00
const onlyInHomeWithdrawals = foreignToHomeConfirmations.filter(eventWithoutReference(foreignToHomeRequests))
const onlyInForeignWithdrawals = foreignToHomeRequests.filter(eventWithoutReference(foreignToHomeConfirmations))
2019-05-08 16:12:02 +03:00
const unclaimedStats = {}
if (MONITOR_HOME_TO_FOREIGN_ALLOWANCE_LIST || MONITOR_HOME_TO_FOREIGN_BLOCK_LIST) {
const unclaimedFilter = unclaimedHomeToForeignRequests()
if (MONITOR_HOME_TO_FOREIGN_CHECK_SENDER === 'true') {
for (let i = 0; i < onlyInHomeDeposits.length; i++) {
onlyInHomeDeposits[i].sender = await getHomeTxSender(onlyInHomeDeposits[i].transactionHash)
}
}
unclaimedStats.unclaimedHomeDeposits = onlyInHomeDeposits.filter(unclaimedFilter)
onlyInHomeDeposits = onlyInHomeDeposits.filter(e => !unclaimedFilter(e))
}
2019-09-18 22:45:13 +03:00
return {
onlyInHomeDeposits,
onlyInForeignDeposits,
onlyInHomeWithdrawals,
onlyInForeignWithdrawals,
...unclaimedStats,
2019-09-18 22:45:13 +03:00
lastChecked: Math.floor(Date.now() / 1000)
}
2019-05-08 16:12:02 +03:00
}
}
module.exports = main