Unverified Commit e0bbe787 authored by yann300's avatar yann300 Committed by GitHub

Merge pull request #774 from ethereum/useEthersForABICoding

Fix bug using ethers.js
parents bc14b301 84ca4569
......@@ -66,16 +66,20 @@ class EventsDecoder {
_decodeEvents (tx, logs, contractName, compiledContracts, cb) {
var eventsABI = this._eventsABI(compiledContracts)
var events = {}
var events = []
for (var i in logs) {
// [address, topics, mem]
var log = logs[i]
var topicId = log.topics[0]
var abi = this._event(topicId.replace('0x', ''), eventsABI)
var topics = log.topics.map((value) => {
return value.indexOf('0x') === 0 ? value : '0x' + value
})
events = abi.object.parse(topics, '0x' + log.data)
if (abi) {
var topics = log.topics.map((value) => {
return value.indexOf('0x') === 0 ? value : '0x' + value
})
events.push({ topic: topicId, event: abi.event, args: abi.object.parse(topics, '0x' + log.data) })
} else {
events.push({ data: log.data, topics: log.topics })
}
}
cb(null, { decoded: events, raw: logs })
}
......
......@@ -243,6 +243,7 @@ module.exports = {
outputTypes.push(fnabi.outputs[i].type)
}
if (!response.length) response = new Uint8Array(32 * fnabi.outputs.length) // ensuring the data is at least filled by 0 cause `AbiCoder` throws if there's not engouh data
// decode data
var abiCoder = new ethers.utils.AbiCoder()
var decodedObj = abiCoder.decode(outputTypes, response)
......
......@@ -325,6 +325,8 @@ class TxListener {
_decodeInputParams (data, abi) {
data = ethJSUtil.toBuffer('0x' + data)
if (!data.length) data = new Uint8Array(32 * abi.inputs.length) // ensuring the data is at least filled by 0 cause `AbiCoder` throws if there's not engouh data
var inputTypes = []
for (var i = 0; i < abi.inputs.length; i++) {
inputTypes.push(abi.inputs[i].type)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment