Last active
September 22, 2019 11:23
-
-
Save leonprou/697d16fe5c4387d452773b2a90481e57 to your computer and use it in GitHub Desktop.
decode logs of web3js contract to events
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const isArray = require('lodash/isArray') | |
const logsToEvents = (logs, contract) => { | |
if (isArray(logs)) { | |
const events = {} | |
logs.forEach((log, index) => { | |
log = contract.events.allEventsLogDecoder.decode(contract.abiModel, log) | |
if (log.event) { | |
if (events[log.event]) { | |
if (isArray(events[log.event])) { | |
events[log.event].push(log) | |
return | |
} | |
events[log.event] = [events[log.event], log] | |
return | |
} | |
events[log.event] = log | |
return | |
} | |
events[index] = log | |
}) | |
return events | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment