-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Adding "codeFile" parameter into aleth-vm options #5848
Conversation
Codecov Report
@@ Coverage Diff @@
## master #5848 +/- ##
==========================================
- Coverage 64.07% 64.05% -0.02%
==========================================
Files 362 362
Lines 30900 30912 +12
Branches 3432 3433 +1
==========================================
+ Hits 19800 19802 +2
- Misses 9874 9881 +7
- Partials 1226 1229 +3 |
36f029e
to
8661e0a
Compare
aleth-vm/main.cpp
Outdated
{ | ||
if (!code.empty()) | ||
cerr << "--code argument overwritten by input file " << inputFile << '\n'; | ||
cerr << "--code argument overwritten by input file " << codeFile << '\n'; |
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.
Please better in case both --code
and --codefile
are present, output an error and exit.
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.
did the change.
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.
So you need now to remove this if (!code.empty())
here, it will never be true
aleth-vm/main.cpp
Outdated
if (inputFile == "-") | ||
for (int i = cin.get(); i != -1; i = cin.get()) | ||
code.push_back(static_cast<byte>(i)); | ||
string codeStr = ""; |
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.
I think it would be simpler to use a single string
variable instead of code
and codeStr
.
So try changing code
to string
, use it for getline
and change line 255 to code = contentsString(codeFile)
.
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.
doing this amendment will make the try/catch block unusable so I removed it.
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.
What do you mean? We need that block, it decodes the hex string.
We should keep it, but it should decode the string that we have read either from file or from command line.
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.
@gumb0 will do the changes, what you said totally make sense, I was really getting of myself, my apologies.
- change placeholder to <path>. - use of single string for code. - try catch removed since ::erase might not throw. - add error message for using --code and --codefile at the same time.
@gumb0 after amendments from review. I got the output below. It seems to be different from what you mentioned on gitter.
|
That's because now without hex decoding, the file is treated as binary, it tries to execute the opcode 54 which is the ascii code of the symbol |
d4bf363
to
f49f6f5
Compare
@gumb0 output code from code form latest changes.
|
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.
Also could you please add a entry to https://github.com/ethereum/aleth/blob/master/CHANGELOG.md describing how the command line changed
aleth-vm/main.cpp
Outdated
std::string strCode{reinterpret_cast<char const*>(code.data()), code.size()}; | ||
strCode.erase(strCode.find_last_not_of(" \t\n\r") + 1); // Right trim. | ||
code = fromHex(strCode, WhenError::Throw); | ||
code.erase(code.find_last_not_of(" \t\n\r") + 1); // Right trim. |
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.
Currently try
/catch
around this is useless (erase
and code
never throw), it was here to handle errors trown by fromHex
.
It's fine that you moved fromHex
into a single place for both --code
and --codefile
, but there needs to be hanlding of exceptions around it.
I guess you would need some new variable like bytes codeBytes
and you would assign result fromHex
to it inside try/catch
, then pass codeBytes
to setCode
.
Also I find it strange that we ignored decoding errors before, so I'd say inside catch
we should better output error and exit.
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.
@gumb0 Changes pushed in the latest commit, please review if I understood your requirements perfectly. Thanks.
aleth-vm/main.cpp
Outdated
{ | ||
if (!code.empty()) | ||
cerr << "--code argument overwritten by input file " << inputFile << '\n'; | ||
if (vm.count("code")) |
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.
this would be more efficient
if (vm.count("code")) | |
if (!code.empty()) |
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.
Noted on this.
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.
@gumb0 Added on latest commit.
Should this be changed on the same pull request? |
Yes, exactly |
- Added changelog for added parameter change. - Made some revisions based on review.
@gumb0 Thanks for correcting my changes, and thanks for the review. |
4ffb887
to
a4e6d35
Compare
@josephnicholas thank you for the contribution. |
Changes:
--codeFile
parameter and accept input file.--codeFile
has-
.Open for reviews and modifications on this PR.
Part of #4613