From a37e48bdca1194e404a4c01503114ddec0697a06 Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 24 Aug 2018 17:10:25 +0200 Subject: [PATCH] remove code duplication && fix "getFunction" --- remix-lib/src/execution/txHelper.js | 5 +++-- remix-lib/src/execution/txListener.js | 27 ++------------------------- 2 files changed, 5 insertions(+), 27 deletions(-) diff --git a/remix-lib/src/execution/txHelper.js b/remix-lib/src/execution/txHelper.js index 938ca2413c..8ad9879acc 100644 --- a/remix-lib/src/execution/txHelper.js +++ b/remix-lib/src/execution/txHelper.js @@ -78,8 +78,9 @@ module.exports = { getFunction: function (abi, fnName) { for (var i = 0; i < abi.length; i++) { - if (abi[i].name === fnName) { - return abi[i] + var fn = abi[i] + if (fn.type === 'function' && fnName === fn.name + '(' + fn.inputs.map((value) => { return value.type }).join(',') + ')') { + return fn } } return null diff --git a/remix-lib/src/execution/txListener.js b/remix-lib/src/execution/txListener.js index 60d00d853e..8864e76294 100644 --- a/remix-lib/src/execution/txListener.js +++ b/remix-lib/src/execution/txListener.js @@ -275,7 +275,7 @@ class TxListener { var methodIdentifiers = contract.object.evm.methodIdentifiers for (var fn in methodIdentifiers) { if (methodIdentifiers[fn] === inputData.substring(0, 8)) { - var fnabi = getFunction(abi, fn) + var fnabi = txHelper.getFunction(abi, fn) this._resolvedTransactions[tx.hash] = { contractName: contractName, to: tx.to, @@ -299,7 +299,7 @@ class TxListener { var bytecode = contract.object.evm.bytecode.object var params = null 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] = { 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