-
Notifications
You must be signed in to change notification settings - Fork 376
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
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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` | ||
|
@@ -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 | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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