Merge pull request #765 from ethereum/fixByteEncoding

Switch abi coder
pull/7/head
yann300 7 years ago committed by GitHub
commit 19275236c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      remix-lib/package.json
  2. 63
      remix-lib/src/execution/eventsDecoder.js
  3. 9
      remix-lib/src/execution/txFormat.js
  4. 16
      remix-lib/src/execution/txHelper.js
  5. 6
      remix-lib/src/execution/txListener.js

@ -15,22 +15,22 @@
"main": "./index.js",
"dependencies": {
"async": "^2.1.2",
"babel-preset-es2015": "^6.24.0",
"babel-plugin-transform-object-assign": "^6.22.0",
"babel-eslint": "^7.1.1",
"babel-plugin-transform-object-assign": "^6.22.0",
"babel-preset-env": "^1.6.1",
"babel-preset-es2015": "^6.24.0",
"babel-preset-stage-0": "^6.24.1",
"babelify": "^7.3.0",
"fast-async": "^6.1.2",
"ethereumjs-util": "^5.1.2",
"ethereumjs-abi": "https://github.com/ethereumjs/ethereumjs-abi",
"ethereumjs-vm": "^2.3.3",
"ethereumjs-block": "^1.6.0",
"ethereumjs-tx": "^1.3.3",
"web3": "^0.18.0",
"ethereumjs-util": "^5.1.2",
"ethereumjs-vm": "^2.3.3",
"ethers": "^3.0.15",
"fast-async": "^6.1.2",
"solc": "^0.4.13",
"standard": "^7.0.1",
"tape": "^4.6.0"
"tape": "^4.6.0",
"web3": "^0.18.0"
},
"scripts": {
"test": "standard && tape ./test/tests.js"

@ -1,5 +1,6 @@
'use strict'
var ethJSABI = require('ethereumjs-abi')
var ethJSUtil = require('ethereumjs-util')
var ethers = require('ethers')
var txHelper = require('./txHelper')
/**
@ -38,13 +39,11 @@ class EventsDecoder {
_eventABI (contract) {
var eventABI = {}
contract.abi.forEach(function (funABI, i) {
if (funABI.type !== 'event') {
return
}
var hash = ethJSABI.eventID(funABI.name, funABI.inputs.map(function (item) { return item.type }))
eventABI[hash.toString('hex')] = { event: funABI.name, inputs: funABI.inputs }
})
var abi = new ethers.Interface(contract.abi)
for (var e in abi.events) {
var event = abi.events[e]
eventABI[ethJSUtil.sha3(new Buffer(event.signature)).toString('hex')] = { event: event.name, inputs: event.inputs, object: event }
}
return eventABI
}
@ -67,54 +66,16 @@ 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)
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]
if (typeof decoded[index] !== 'string') {
decoded[index] = ethJSABI.stringify([item.type], decoded[index])
}
} catch (e) {
decoded[index] = encodedData
}
indexed++
} else {
nonindexed.push(item.type)
}
})
// decode non indexed param
var nonindexededResult = ethJSABI.rawDecode(nonindexed, new Buffer(log.data.replace('0x', ''), 'hex'))
nonindexed = ethJSABI.stringify(nonindexed, nonindexededResult)
// 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({ topic: topicId, event: event, args: decoded })
} else {
events.push({ data: log.data, topics: log.topics })
}
var topics = log.topics.map((value) => {
return value.indexOf('0x') === 0 ? value : '0x' + value
})
events = abi.object.parse(topics, '0x' + log.data)
}
cb(null, { decoded: events, raw: logs })
}

@ -1,5 +1,5 @@
'use strict'
var ethJSABI = require('ethereumjs-abi')
var ethers = require('ethers')
var helper = require('./txHelper')
var executionContext = require('./execution-context')
var asyncJS = require('async')
@ -96,7 +96,7 @@ module.exports = {
dataHex = bytecodeToDeploy + dataHex
}
} else {
dataHex = Buffer.concat([helper.encodeFunctionId(funAbi), data]).toString('hex')
dataHex = helper.encodeFunctionId(funAbi) + dataHex
}
callback(null, { dataHex, funAbi, funArgs, contractBytecode, contractName: contractName })
},
@ -244,10 +244,9 @@ module.exports = {
}
// decode data
var decodedObj = ethJSABI.rawDecode(outputTypes, response)
var abiCoder = new ethers.utils.AbiCoder()
var decodedObj = abiCoder.decode(outputTypes, response)
// format decoded data
decodedObj = ethJSABI.stringify(outputTypes, decodedObj)
var json = {}
for (i = 0; i < outputTypes.length; i++) {
var name = fnabi.outputs[i].name

@ -1,5 +1,5 @@
'use strict'
var ethJSABI = require('ethereumjs-abi')
var ethers = require('ethers')
module.exports = {
encodeParams: function (funABI, args) {
@ -16,18 +16,14 @@ module.exports = {
// NOTE: the caller will concatenate the bytecode and this
// it could be done here too for consistency
return ethJSABI.rawEncode(types, args)
var abiCoder = new ethers.utils.AbiCoder()
return abiCoder.encode(types, args)
},
encodeFunctionId: function (funABI) {
var types = []
if (funABI.inputs && funABI.inputs.length) {
for (var i = 0; i < funABI.inputs.length; i++) {
types.push(funABI.inputs[i].type)
}
}
return ethJSABI.methodID(funABI.name, types)
var abi = new ethers.Interface([funABI])
abi = abi.functions[funABI.name]
return abi.sighash
},
sortAbiFunction: function (contractabi) {

@ -1,6 +1,6 @@
'use strict'
var async = require('async')
var ethJSABI = require('ethereumjs-abi')
var ethers = require('ethers')
var ethJSUtil = require('ethereumjs-util')
var EventManager = require('../eventManager')
var codeUtil = require('../util')
@ -329,8 +329,8 @@ class TxListener {
for (var i = 0; i < abi.inputs.length; i++) {
inputTypes.push(abi.inputs[i].type)
}
var decoded = ethJSABI.rawDecode(inputTypes, data)
decoded = ethJSABI.stringify(inputTypes, decoded)
var abiCoder = new ethers.utils.AbiCoder()
var decoded = abiCoder.decode(inputTypes, data)
var ret = {}
for (var k in abi.inputs) {
ret[abi.inputs[k].type + ' ' + abi.inputs[k].name] = decoded[k]

Loading…
Cancel
Save