Formatting input parameters

This commit is contained in:
Richard Ramos 2018-06-08 16:34:35 -04:00
parent 610b6de008
commit 87a49900b4
2 changed files with 31 additions and 8 deletions

View File

@ -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);
}

View File

@ -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,