2019-09-18 22:45:13 +03:00
|
|
|
const web3Utils = require('web3').utils
|
2020-05-21 23:29:56 +03:00
|
|
|
const { parseAMBMessage } = require('../../commons')
|
2019-09-18 22:45:13 +03:00
|
|
|
|
|
|
|
function deliveredMsgNotProcessed(processedList) {
|
|
|
|
return deliveredMsg => {
|
2020-06-10 16:22:01 +03:00
|
|
|
let msgData = deliveredMsg.returnValues.encodedData
|
|
|
|
if (!deliveredMsg.returnValues.messageId) {
|
|
|
|
// append tx hash to an old message, where message id was not used
|
|
|
|
msgData = deliveredMsg.transactionHash + msgData.slice(2)
|
|
|
|
}
|
|
|
|
const msg = parseAMBMessage(msgData)
|
2019-09-18 22:45:13 +03:00
|
|
|
return (
|
|
|
|
processedList.filter(processedMsg => {
|
|
|
|
return messageEqualsEvent(msg, processedMsg.returnValues)
|
|
|
|
}).length === 0
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function processedMsgNotDelivered(deliveredList) {
|
|
|
|
return processedMsg => {
|
|
|
|
return (
|
|
|
|
deliveredList.filter(deliveredMsg => {
|
2020-06-10 16:22:01 +03:00
|
|
|
let msgData = deliveredMsg.returnValues.encodedData
|
|
|
|
if (!deliveredMsg.returnValues.messageId) {
|
|
|
|
// append tx hash to an old message, where message id was not used
|
|
|
|
msgData = deliveredMsg.transactionHash + msgData.slice(2)
|
|
|
|
}
|
|
|
|
const msg = parseAMBMessage(msgData)
|
2019-09-18 22:45:13 +03:00
|
|
|
return messageEqualsEvent(msg, processedMsg.returnValues)
|
|
|
|
}).length === 0
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function messageEqualsEvent(parsedMsg, event) {
|
|
|
|
return (
|
|
|
|
web3Utils.toChecksumAddress(parsedMsg.sender) === event.sender &&
|
|
|
|
web3Utils.toChecksumAddress(parsedMsg.executor) === event.executor &&
|
2020-06-10 16:22:01 +03:00
|
|
|
parsedMsg.messageId === event.messageId // for an old messages, event.messageId is actually a transactionHash
|
2019-09-18 22:45:13 +03:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-10-29 22: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
|
|
|
|
})
|
|
|
|
|
|
|
|
const eventWithoutReference = otherSideEvents => e =>
|
|
|
|
otherSideEvents.filter(a => a.referenceTx === e.referenceTx && a.recipient === e.recipient && a.value === e.value)
|
|
|
|
.length === 0
|
|
|
|
|
2019-09-18 22:45:13 +03:00
|
|
|
module.exports = {
|
|
|
|
deliveredMsgNotProcessed,
|
2019-10-29 22:22:02 +03:00
|
|
|
processedMsgNotDelivered,
|
|
|
|
normalizeEventInformation,
|
|
|
|
eventWithoutReference
|
2019-09-18 22:45:13 +03:00
|
|
|
}
|