|
|
|
@ -1,5 +1,4 @@ |
|
|
|
|
'use strict' |
|
|
|
|
var ethJSUtil = require('ethereumjs-util') |
|
|
|
|
var ethers = require('ethers') |
|
|
|
|
var txHelper = require('./txHelper') |
|
|
|
|
|
|
|
|
@ -39,10 +38,10 @@ class EventsDecoder { |
|
|
|
|
|
|
|
|
|
_eventABI (contract) { |
|
|
|
|
var eventABI = {} |
|
|
|
|
var abi = new ethers.Interface(contract.abi) |
|
|
|
|
var abi = new ethers.utils.Interface(contract.abi) |
|
|
|
|
for (var e in abi.events) { |
|
|
|
|
var event = abi.events[e] |
|
|
|
|
eventABI[ethJSUtil.sha3(Buffer.from(event.signature)).toString('hex')] = { event: event.name, inputs: event.inputs, object: event } |
|
|
|
|
eventABI[event.topic.replace('0x', '')] = { event: event.name, inputs: event.inputs, object: event, abi: abi } |
|
|
|
|
} |
|
|
|
|
return eventABI |
|
|
|
|
} |
|
|
|
@ -71,9 +70,17 @@ class EventsDecoder { |
|
|
|
|
// [address, topics, mem]
|
|
|
|
|
var log = logs[i] |
|
|
|
|
var topicId = log.topics[0] |
|
|
|
|
var abi = this._event(topicId.replace('0x', ''), eventsABI) |
|
|
|
|
if (abi) { |
|
|
|
|
events.push({ from: log.address, topic: topicId, event: abi.event, args: abi.object.parse(log.topics, log.data) }) |
|
|
|
|
var eventAbi = this._event(topicId.replace('0x', ''), eventsABI) |
|
|
|
|
if (eventAbi) { |
|
|
|
|
var decodedlog = eventAbi.abi.parseLog(log) |
|
|
|
|
let decoded = {} |
|
|
|
|
for (const v in decodedlog.values) { |
|
|
|
|
const value = decodedlog.values[v] |
|
|
|
|
if (value._ethersType) value.type = value._ethersType |
|
|
|
|
let decodedValue = value._ethersType === 'BigNumber' ? value.toString() : value |
|
|
|
|
decoded[v] = decodedValue |
|
|
|
|
} |
|
|
|
|
events.push({ from: log.address, topic: topicId, event: eventAbi.event, args: decoded }) |
|
|
|
|
} else { |
|
|
|
|
events.push({ from: log.address, data: log.data, topics: log.topics }) |
|
|
|
|
} |
|
|
|
|