2020-12-20 01:19:49 +03:00
|
|
|
const { normalizeAMBMessageEvent } = require('../../commons')
|
2020-10-29 11:25:43 +03:00
|
|
|
const { readAccessListFile } = require('./file')
|
|
|
|
|
|
|
|
const { MONITOR_HOME_TO_FOREIGN_ALLOWANCE_LIST, MONITOR_HOME_TO_FOREIGN_BLOCK_LIST } = process.env
|
2019-09-18 16:45:13 -03:00
|
|
|
|
2020-10-23 13:48:37 +03:00
|
|
|
const keyAMB = e => [e.messageId, e.sender, e.executor].join(',').toLowerCase()
|
|
|
|
|
|
|
|
function deliveredMsgNotProcessed(processedList) {
|
|
|
|
const keys = new Set()
|
|
|
|
processedList.forEach(processedMsg => keys.add(keyAMB(processedMsg.returnValues)))
|
2020-12-20 01:19:49 +03:00
|
|
|
return deliveredMsg => !keys.has(keyAMB(normalizeAMBMessageEvent(deliveredMsg)))
|
2019-09-18 16:45:13 -03:00
|
|
|
}
|
|
|
|
|
2020-10-23 13:48:37 +03:00
|
|
|
function processedMsgNotDelivered(deliveredList) {
|
|
|
|
const keys = new Set()
|
2020-12-20 01:19:49 +03:00
|
|
|
deliveredList.forEach(deliveredMsg => keys.add(keyAMB(normalizeAMBMessageEvent(deliveredMsg))))
|
2020-10-23 13:48:37 +03:00
|
|
|
return processedMsg => !keys.has(keyAMB(processedMsg.returnValues))
|
2019-09-18 16:45:13 -03:00
|
|
|
}
|
|
|
|
|
2020-12-20 01:19:49 +03:00
|
|
|
function addExecutionStatus(processedList) {
|
|
|
|
const statuses = {}
|
|
|
|
processedList.forEach(processedMsg => {
|
|
|
|
statuses[keyAMB(processedMsg.returnValues)] = processedMsg.returnValues.status
|
|
|
|
})
|
|
|
|
return deliveredMsg => {
|
|
|
|
deliveredMsg.status = statuses[keyAMB(deliveredMsg)]
|
|
|
|
return deliveredMsg
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-26 21:58:20 +07:00
|
|
|
function addRetrievalStatus(retrievedInfoList) {
|
|
|
|
const statuses = {}
|
|
|
|
retrievedInfoList.forEach(e => {
|
|
|
|
statuses[e.returnValues.messageId] = {
|
|
|
|
callStatus: e.returnValues.status,
|
|
|
|
callbackStatus: e.returnValues.callbackStatus
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return deliveredMsg => {
|
|
|
|
deliveredMsg.callStatus = statuses[deliveredMsg.messageId].callStatus
|
|
|
|
deliveredMsg.callbackStatus = statuses[deliveredMsg.messageId].callbackStatus
|
|
|
|
return deliveredMsg
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-29 16:22:02 -03:00
|
|
|
/**
|
|
|
|
* Normalizes the different event objects to facilitate data processing
|
|
|
|
* @param {Object} event
|
|
|
|
* @returns {{
|
|
|
|
* transactionHash: string,
|
|
|
|
* blockNumber: number,
|
|
|
|
* referenceTx: string,
|
|
|
|
* recipient: string | *,
|
|
|
|
* value: *
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
const normalizeEventInformation = event => ({
|
|
|
|
transactionHash: event.transactionHash,
|
|
|
|
blockNumber: event.blockNumber,
|
|
|
|
referenceTx: event.returnValues.transactionHash || event.transactionHash,
|
|
|
|
recipient: event.returnValues.recipient || event.returnValues.from,
|
|
|
|
value: event.returnValues.value
|
|
|
|
})
|
|
|
|
|
2020-10-23 13:48:37 +03:00
|
|
|
const key = e => [e.referenceTx, e.recipient, e.value].join(',').toLowerCase()
|
|
|
|
|
|
|
|
const eventWithoutReference = otherSideEvents => {
|
|
|
|
const keys = new Set()
|
|
|
|
otherSideEvents.forEach(e => keys.add(key(e)))
|
|
|
|
return e => !keys.has(key(e))
|
|
|
|
}
|
2019-10-29 16:22:02 -03:00
|
|
|
|
2020-10-29 11:25:43 +03:00
|
|
|
const unclaimedHomeToForeignRequests = () => {
|
|
|
|
if (MONITOR_HOME_TO_FOREIGN_ALLOWANCE_LIST) {
|
|
|
|
const allowanceList = readAccessListFile(MONITOR_HOME_TO_FOREIGN_ALLOWANCE_LIST)
|
|
|
|
return e => !allowanceList.includes(e.recipient.toLowerCase()) && !(e.sender && allowanceList.includes(e.sender))
|
|
|
|
} else if (MONITOR_HOME_TO_FOREIGN_BLOCK_LIST) {
|
|
|
|
const blockList = readAccessListFile(MONITOR_HOME_TO_FOREIGN_BLOCK_LIST)
|
|
|
|
return e => blockList.includes(e.recipient.toLowerCase()) || (e.sender && blockList.includes(e.sender))
|
|
|
|
} else {
|
|
|
|
return () => false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-04 22:16:43 +03:00
|
|
|
const manuallyProcessedAMBHomeToForeignRequests = () => {
|
|
|
|
if (MONITOR_HOME_TO_FOREIGN_ALLOWANCE_LIST) {
|
|
|
|
const allowanceList = readAccessListFile(MONITOR_HOME_TO_FOREIGN_ALLOWANCE_LIST)
|
|
|
|
return e => {
|
2020-12-20 01:19:49 +03:00
|
|
|
const { sender, executor, decodedDataType } = normalizeAMBMessageEvent(e)
|
2020-11-04 22:16:43 +03:00
|
|
|
return (!allowanceList.includes(sender) && !allowanceList.includes(executor)) || decodedDataType.manualLane
|
|
|
|
}
|
|
|
|
} else if (MONITOR_HOME_TO_FOREIGN_BLOCK_LIST) {
|
|
|
|
const blockList = readAccessListFile(MONITOR_HOME_TO_FOREIGN_BLOCK_LIST)
|
|
|
|
return e => {
|
2020-12-20 01:19:49 +03:00
|
|
|
const { sender, executor, decodedDataType } = normalizeAMBMessageEvent(e)
|
2020-11-04 22:16:43 +03:00
|
|
|
return blockList.includes(sender) || blockList.includes(executor) || decodedDataType.manualLane
|
|
|
|
}
|
|
|
|
} else {
|
2020-12-20 01:19:49 +03:00
|
|
|
return e => normalizeAMBMessageEvent(e).decodedDataType.manualLane
|
2020-11-04 22:16:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-18 16:45:13 -03:00
|
|
|
module.exports = {
|
|
|
|
deliveredMsgNotProcessed,
|
2019-10-29 16:22:02 -03:00
|
|
|
processedMsgNotDelivered,
|
2020-12-20 01:19:49 +03:00
|
|
|
addExecutionStatus,
|
2021-05-26 21:58:20 +07:00
|
|
|
addRetrievalStatus,
|
2019-10-29 16:22:02 -03:00
|
|
|
normalizeEventInformation,
|
2020-10-29 11:25:43 +03:00
|
|
|
eventWithoutReference,
|
2020-11-04 22:16:43 +03:00
|
|
|
unclaimedHomeToForeignRequests,
|
|
|
|
manuallyProcessedAMBHomeToForeignRequests
|
2019-09-18 16:45:13 -03:00
|
|
|
}
|