diff --git a/lib/modules/console_listener/index.js b/lib/modules/console_listener/index.js index 00cfbaf7a..5fd1a3ec6 100644 --- a/lib/modules/console_listener/index.js +++ b/lib/modules/console_listener/index.js @@ -18,12 +18,18 @@ class ConsoleListener { let funcSignatures = {}; contract.abiDefinition .filter(func => func.type == "function") - .map(func => func.name + - '(' + - (func.inputs ? func.inputs.map(input => input.type).join(',') : '') + - ')') + .map(func => { + return { + name: func.name + + '(' + + (func.inputs ? func.inputs.map(input => input.type).join(',') : '') + + ')', + abi: func, + functionName: func.name + }; + }) .forEach(func => { - funcSignatures[utils.sha3(func).substring(0, 10)] = func; + funcSignatures[utils.sha3(func.name).substring(0, 10)] = func; }); this.addressToContract[address] = { @@ -44,12 +50,23 @@ class ConsoleListener { } let name = this.addressToContract[address].name; - let funcHash = this.addressToContract[address].functions[data.substring(0, 10)]; - + let func = this.addressToContract[address].functions[data.substring(0, 10)]; + let functionName = func.functionName; + + let decodedParameters = utils.decodeParams(func.abi.inputs, data.substring(10)); + let paramString = ""; + if(func.abi.inputs){ + func.abi.inputs.forEach((input) => { + let quote = input.type.indexOf("int") == -1 ? '"' : ''; + paramString += quote + decodedParameters[input.name] + quote + ", "; + }); + paramString = paramString.substring(0, paramString.length - 2); + } + gasUsed = utils.hexToNumber(gasUsed); blockNumber = utils.hexToNumber(blockNumber); - this.logger.debug(`${name}.${funcHash} : ${transactionHash} | gas:${gasUsed} | blk:${blockNumber} | status:${status}`); + this.logger.debug(`${name}.${functionName}(${paramString}) : ${transactionHash} | gas:${gasUsed} | blk:${blockNumber} | status:${status}`); } else { this.logger.debug(request); } diff --git a/lib/utils/utils.js b/lib/utils/utils.js index a57b3ba5b..3a0a90202 100644 --- a/lib/utils/utils.js +++ b/lib/utils/utils.js @@ -7,6 +7,7 @@ let shelljs = require('shelljs'); var tar = require('tar'); var propose = require('propose'); var Web3 = require('web3'); +var Web3EthAbi = require('web3-eth-abi'); const constants = require('../constants'); //let fs = require('../core/fs.js'); @@ -189,6 +190,10 @@ function hexToNumber(hex){ return Web3.utils.hexToNumber(hex); } +function decodeParams(typesArray, hexString){ + return Web3EthAbi.decodeParameters(typesArray, hexString); +} + function toChecksumAddress(address) { return Web3.utils.toChecksumAddress(address); } @@ -258,6 +263,7 @@ module.exports = { httpGetJson: httpGetJson, httpsGetJson: httpsGetJson, hexToNumber: hexToNumber, + decodeParams: decodeParams, runCmd: runCmd, cd: cd, sed: sed,