remove code duplication && fix "getFunction"

pull/5370/head
yann300 6 years ago
parent 6ca3a92876
commit 728309d679
  1. 5
      remix-lib/src/execution/txHelper.js
  2. 27
      remix-lib/src/execution/txListener.js

@ -78,8 +78,9 @@ module.exports = {
getFunction: function (abi, fnName) { getFunction: function (abi, fnName) {
for (var i = 0; i < abi.length; i++) { for (var i = 0; i < abi.length; i++) {
if (abi[i].name === fnName) { var fn = abi[i]
return abi[i] if (fn.type === 'function' && fnName === fn.name + '(' + fn.inputs.map((value) => { return value.type }).join(',') + ')') {
return fn
} }
} }
return null return null

@ -275,7 +275,7 @@ class TxListener {
var methodIdentifiers = contract.object.evm.methodIdentifiers var methodIdentifiers = contract.object.evm.methodIdentifiers
for (var fn in methodIdentifiers) { for (var fn in methodIdentifiers) {
if (methodIdentifiers[fn] === inputData.substring(0, 8)) { if (methodIdentifiers[fn] === inputData.substring(0, 8)) {
var fnabi = getFunction(abi, fn) var fnabi = txHelper.getFunction(abi, fn)
this._resolvedTransactions[tx.hash] = { this._resolvedTransactions[tx.hash] = {
contractName: contractName, contractName: contractName,
to: tx.to, to: tx.to,
@ -299,7 +299,7 @@ class TxListener {
var bytecode = contract.object.evm.bytecode.object var bytecode = contract.object.evm.bytecode.object
var params = null var params = null
if (bytecode && bytecode.length) { if (bytecode && bytecode.length) {
params = this._decodeInputParams(inputData.substring(bytecode.length), getConstructorInterface(abi)) params = this._decodeInputParams(inputData.substring(bytecode.length), txHelper.getConstructorInterface(abi))
} }
this._resolvedTransactions[tx.hash] = { this._resolvedTransactions[tx.hash] = {
contractName: contractName, contractName: contractName,
@ -342,27 +342,4 @@ class TxListener {
} }
} }
// those function will be duplicate after the merged of the compile and run tabs split
function getConstructorInterface (abi) {
var funABI = { 'name': '', 'inputs': [], 'type': 'constructor', 'outputs': [] }
for (var i = 0; i < abi.length; i++) {
if (abi[i].type === 'constructor') {
funABI.inputs = abi[i].inputs || []
break
}
}
return funABI
}
function getFunction (abi, fnName) {
for (var i = 0; i < abi.length; i++) {
var fn = abi[i]
if (fnName === fn.name + '(' + fn.inputs.map((value) => { return value.type }).join(',') + ')') {
return fn
}
}
return null
}
module.exports = TxListener module.exports = TxListener

Loading…
Cancel
Save