From 8661e0add0df57ca64f614a39c717f1e4cbb693c Mon Sep 17 00:00:00 2001 From: "JOSEPH NICHOLAS R. ALCANTARA" Date: Sun, 24 Nov 2019 01:23:57 +0800 Subject: [PATCH] Adding "codeFile" parameter into alet-vm options Part of https://github.com/ethereum/aleth/issues/4613 --- aleth-vm/main.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/aleth-vm/main.cpp b/aleth-vm/main.cpp index 8311efbdc7c..a8e366a6cc2 100644 --- a/aleth-vm/main.cpp +++ b/aleth-vm/main.cpp @@ -73,7 +73,7 @@ class LastBlockHashes : public eth::LastBlockHashesFace int main(int argc, char** argv) { setDefaultOrCLocale(); - string inputFile; + string codeFile; Mode mode = Mode::Statistics; State state(0); Address sender = Address(69); @@ -113,6 +113,7 @@ int main(int argc, char** argv) addTransactionOption("input", po::value(), " Transaction code should be "); addTransactionOption("code", po::value(), " Contract code . Makes transaction a call to this contract"); + addTransactionOption("codefile", po::value(), " File containing EVM code . If '-' is specified, code is read from stdin"); po::options_description networkOptions("Network options", c_lineWidth); networkOptions.add_options()("network", po::value(), @@ -174,8 +175,6 @@ int main(int argc, char** argv) mode = Mode::Trace; else if (arg == "test") mode = Mode::Test; - else if (inputFile.empty()) - inputFile = arg; // Assign input file name only once. else { cerr << "Unknown argument: " << arg << '\n'; @@ -240,22 +239,24 @@ int main(int argc, char** argv) data = fromHex(vm["input"].as()); if (vm.count("code")) code = fromHex(vm["code"].as()); + if (vm.count("codefile")) + codeFile = vm["codefile"].as(); // Read code from input file. - if (!inputFile.empty()) + if (!codeFile.empty()) { if (!code.empty()) - cerr << "--code argument overwritten by input file " << inputFile << '\n'; + cerr << "--code argument overwritten by input file " << codeFile << '\n'; - if (inputFile == "-") - for (int i = cin.get(); i != -1; i = cin.get()) - code.push_back(static_cast(i)); + string codeStr = ""; + if (codeFile == "-") + std::getline(std::cin, codeStr); else - code = contents(inputFile); + code = contents(codeFile); try // Try decoding from hex. { - std::string strCode{reinterpret_cast(code.data()), code.size()}; + std::string strCode = codeFile == "-" ? codeStr : string(reinterpret_cast(code.data()), code.size()); strCode.erase(strCode.find_last_not_of(" \t\n\r") + 1); // Right trim. code = fromHex(strCode, WhenError::Throw); }