Merge pull request #794 from ethereum/ide

support indexed event
pull/1/head
yann300 7 years ago committed by GitHub
commit 20e3ca65b5
  1. 53
      src/app/execution/eventsDecoder.js
  2. 8
      src/app/execution/txLogger.js

@ -50,26 +50,49 @@ class EventsDecoder {
_decodeEvents (tx, logs, contractName, compiledContracts, cb) {
var eventABI = this._eventABI(contractName, compiledContracts)
// FIXME: support indexed events
var events = []
for (var i in logs) {
// [address, topics, mem]
var log = logs[i]
var event
var decoded
try {
var abi = eventABI[log.topics[0].replace('0x', '')]
event = abi.event
var types = abi.inputs.map(function (item) {
return item.type
})
decoded = ethJSABI.rawDecode(types, new Buffer(log.data.replace('0x', ''), 'hex'))
decoded = ethJSABI.stringify(types, decoded)
} catch (e) {
decoded = log.data
var abi = eventABI[log.topics[0].replace('0x', '')]
if (abi) {
var event
try {
var decoded = new Array(abi.inputs.length)
event = abi.event
var indexed = 1
var nonindexed = []
// decode indexed param
abi.inputs.map(function (item, index) {
if (item.indexed) {
var encodedData = log.topics[indexed].replace('0x', '')
try {
decoded[index] = ethJSABI.rawDecode([item.type], new Buffer(encodedData, 'hex'))[0]
} catch (e) {
decoded[index] = encodedData
}
indexed++
} else {
nonindexed.push(item.type)
}
})
// decode non indexed param
nonindexed = ethJSABI.rawDecode(nonindexed, new Buffer(log.data.replace('0x', ''), 'hex'))
// ordering
var j = 0
abi.inputs.map(function (item, index) {
if (!item.indexed) {
decoded[index] = nonindexed[j]
j++
}
})
} catch (e) {
decoded = log.data
}
events.push({ event: event, args: decoded })
} else {
events.push({ data: log.data, topics: log.topics })
}
events.push({ event: event, args: decoded })
}
cb(null, { decoded: events, raw: logs })
}

@ -381,12 +381,16 @@ function createTable (opts) {
table.appendChild(outputDecoded)
}
var stringified = ' - '
if (opts.logs.decoded) {
stringified = value(opts.logs.decoded)
}
var logs = yo`
<tr class="${css.tr}">
<td class="${css.td}"> logs </td>
<td class="${css.td}">
<i class="fa fa-clipboard ${css.clipboardCopy}" aria-hidden="true" onclick=${function () { copy(JSON.stringify(opts.logs.decoded || [], null, '\t')) }} title='Copy Logs to clipboard'></i>
<i class="fa fa-clipboard ${css.clipboardCopy}" aria-hidden="true" onclick=${function () { copy(JSON.stringify(opts.logs.raw || '0')) }} title='Copy Raw Logs to clipboard'></i>${JSON.stringify(opts.logs.decoded || [], null, '\t')}</td>
<i class="fa fa-clipboard ${css.clipboardCopy}" aria-hidden="true" onclick=${function () { copy(JSON.stringify(stringified, null, '\t')) }} title='Copy Logs to clipboard'></i>
<i class="fa fa-clipboard ${css.clipboardCopy}" aria-hidden="true" onclick=${function () { copy(JSON.stringify(opts.logs.raw || '0')) }} title='Copy Raw Logs to clipboard'></i>${JSON.stringify(stringified, null, '\t')}</td>
</tr class="${css.tr}">
`
if (opts.logs) table.appendChild(logs)

Loading…
Cancel
Save