Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

decoder: add optional filename param, parse bytes as hex #203

Merged
merged 3 commits into from
Aug 16, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"openzeppelin-solidity": "1.11.0",
"path": "^0.12.7",
"q": "^1.5.1",
"web3": "^1.0.0-beta.35",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to be using the beta version?

Copy link
Contributor Author

@walkerq walkerq Aug 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, just changed it back to latest maintenance version, 0.20.6

"zos-lib": "1.3.0",
"truffle-hdwallet-provider": "^0.0.6"
},
Expand Down
4 changes: 2 additions & 2 deletions scripts/dataEncodingTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ describe('transaction data encoding and decoding tests', function() {
})

it('td006 should decode a data string and output decoded result to a file', async function () {
await exec("truffle exec ./scripts/decodeTxData.js --contract FiatTokenV1 --data " + configureMinterData);
var decodedDataJson = fs.readFileSync('decoded_data/' + configureMinterData + '.json');
await exec("truffle exec ./scripts/decodeTxData.js --contract FiatTokenV1 --data " + configureMinterData + " --filename configureMinterTest");
var decodedDataJson = fs.readFileSync('decoded_data/configureMinterTest.json');
var decodedData = JSON.parse(decodedDataJson);
assert.equal(decodedData.name, "configureMinter")
assert.equal(decodedData.types[0], "address")
Expand Down
14 changes: 12 additions & 2 deletions scripts/decodeTxData.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// args:
// "--contract": name of contract
// "--data": hex used as input data to ethereum transaction. Encodes function name, parameter types, and parameter values
// "--filename": (optional) file name used for output file. If none is supplied, output is only sent to standard output stream

// example:
// `truffle exec decodeTxData.js --contract FiatTokenV1 --data 0x4e44d9560000000000000000000000009c08210cc65b5c9f1961cdbd9ea9bf017522464d000000000000000000000000000000000000000000000000000000003b9aca00`
Expand All @@ -13,13 +14,15 @@ const InputDataDecoder = require('ethereum-input-data-decoder')
var fs = require('fs')
var path = require('path')
var mkdirp = require('mkdirp')
var web3 = require('web3')

var args = process.argv;

var dataFlagIndex = args.indexOf("--data");
var data = args[dataFlagIndex + 1]
var contractNameFlagIndex = args.indexOf("--contract")
var contractName = args[contractNameFlagIndex + 1]
var fileNameFlagIndex = args.indexOf("--filename")

var FiatTokenVX = artifacts.require(contractName)
var abi = FiatTokenVX.abi
Expand All @@ -32,13 +35,20 @@ function decode() {
if ((typeof result.inputs[i] == "object") && result.types[i].includes("uint")) {
result.inputs[i] = result.inputs[i].toString()
}
if (result.types[i] == "bytes") {
result.inputs[i] = web3.utils.bytesToHex(result.inputs[i])
}

}

var decodedDataJson = JSON.stringify(result)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think it should probably write to a file or output to command line, but not both.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, changed

console.log(decodedDataJson)

mkdirp.sync('decoded_data')
fs.writeFileSync('decoded_data/' + data + '.json', decodedDataJson, 'utf8');
if (fileNameFlagIndex != -1) {
fileName = args[fileNameFlagIndex + 1]
mkdirp.sync('decoded_data')
fs.writeFileSync('decoded_data/' + fileName + '.json', decodedDataJson, 'utf8');
}
}

module.exports = async function(callback) {
Expand Down
Loading