Formatting input parameters

This commit is contained in:
Richard Ramos 2018-06-08 16:34:35 -04:00
parent 39d510cef4
commit c9a2014ac7
2 changed files with 31 additions and 8 deletions

View File

@ -18,12 +18,18 @@ class ConsoleListener {
let funcSignatures = {}; let funcSignatures = {};
contract.abiDefinition contract.abiDefinition
.filter(func => func.type == "function") .filter(func => func.type == "function")
.map(func => func.name + .map(func => {
return {
name: func.name +
'(' + '(' +
(func.inputs ? func.inputs.map(input => input.type).join(',') : '') + (func.inputs ? func.inputs.map(input => input.type).join(',') : '') +
')') ')',
abi: func,
functionName: func.name
};
})
.forEach(func => { .forEach(func => {
funcSignatures[utils.sha3(func).substring(0, 10)] = func; funcSignatures[utils.sha3(func.name).substring(0, 10)] = func;
}); });
this.addressToContract[address] = { this.addressToContract[address] = {
@ -44,12 +50,23 @@ class ConsoleListener {
} }
let name = this.addressToContract[address].name; 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); gasUsed = utils.hexToNumber(gasUsed);
blockNumber = utils.hexToNumber(blockNumber); 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 { } else {
this.logger.debug(request); this.logger.debug(request);
} }

View File

@ -7,6 +7,7 @@ let shelljs = require('shelljs');
var tar = require('tar'); var tar = require('tar');
var propose = require('propose'); var propose = require('propose');
var Web3 = require('web3'); var Web3 = require('web3');
var Web3EthAbi = require('web3-eth-abi');
const constants = require('../constants'); const constants = require('../constants');
//let fs = require('../core/fs.js'); //let fs = require('../core/fs.js');
@ -189,6 +190,10 @@ function hexToNumber(hex){
return Web3.utils.hexToNumber(hex); return Web3.utils.hexToNumber(hex);
} }
function decodeParams(typesArray, hexString){
return Web3EthAbi.decodeParameters(typesArray, hexString);
}
function toChecksumAddress(address) { function toChecksumAddress(address) {
return Web3.utils.toChecksumAddress(address); return Web3.utils.toChecksumAddress(address);
} }
@ -258,6 +263,7 @@ module.exports = {
httpGetJson: httpGetJson, httpGetJson: httpGetJson,
httpsGetJson: httpsGetJson, httpsGetJson: httpsGetJson,
hexToNumber: hexToNumber, hexToNumber: hexToNumber,
decodeParams: decodeParams,
runCmd: runCmd, runCmd: runCmd,
cd: cd, cd: cd,
sed: sed, sed: sed,