Create and output clone contracts.

This commit is contained in:
chriseth 2015-07-31 19:23:31 +02:00
parent c11d2a2c62
commit 598e66f395

View File

@ -63,6 +63,7 @@ static string const g_argAsmJsonStr = "asm-json";
static string const g_argAstStr = "ast"; static string const g_argAstStr = "ast";
static string const g_argAstJson = "ast-json"; static string const g_argAstJson = "ast-json";
static string const g_argBinaryStr = "binary"; static string const g_argBinaryStr = "binary";
static string const g_argCloneBinaryStr = "clone-binary";
static string const g_argOpcodesStr = "opcodes"; static string const g_argOpcodesStr = "opcodes";
static string const g_argNatspecDevStr = "natspec-dev"; static string const g_argNatspecDevStr = "natspec-dev";
static string const g_argNatspecUserStr = "natspec-user"; static string const g_argNatspecUserStr = "natspec-user";
@ -71,6 +72,7 @@ static string const g_argAddStandard = "add-std";
/// Possible arguments to for --combined-json /// Possible arguments to for --combined-json
static set<string> const g_combinedJsonArgs{ static set<string> const g_combinedJsonArgs{
"binary", "binary",
"clone-binary",
"opcodes", "opcodes",
"json-abi", "json-abi",
"sol-abi", "sol-abi",
@ -110,7 +112,8 @@ static bool needsHumanTargetedStdout(po::variables_map const& _args)
humanTargetedStdout(_args, g_argAsmStr) || humanTargetedStdout(_args, g_argAsmStr) ||
humanTargetedStdout(_args, g_argAsmJsonStr) || humanTargetedStdout(_args, g_argAsmJsonStr) ||
humanTargetedStdout(_args, g_argOpcodesStr) || humanTargetedStdout(_args, g_argOpcodesStr) ||
humanTargetedStdout(_args, g_argBinaryStr); humanTargetedStdout(_args, g_argBinaryStr) ||
humanTargetedStdout(_args, g_argCloneBinaryStr);
} }
static inline bool outputToFile(OutputType type) static inline bool outputToFile(OutputType type)
@ -140,19 +143,34 @@ static std::istream& operator>>(std::istream& _in, OutputType& io_output)
void CommandLineInterface::handleBinary(string const& _contract) void CommandLineInterface::handleBinary(string const& _contract)
{ {
auto choice = m_args[g_argBinaryStr].as<OutputType>(); if (m_args.count(g_argBinaryStr))
if (outputToStdout(choice)) {
if (outputToStdout(m_args[g_argBinaryStr].as<OutputType>()))
{ {
cout << "Binary: " << endl; cout << "Binary: " << endl;
cout << toHex(m_compiler->getBytecode(_contract)) << endl; cout << toHex(m_compiler->getBytecode(_contract)) << endl;
} }
if (outputToFile(m_args[g_argBinaryStr].as<OutputType>()))
if (outputToFile(choice))
{ {
ofstream outFile(_contract + ".binary"); ofstream outFile(_contract + ".binary");
outFile << toHex(m_compiler->getBytecode(_contract)); outFile << toHex(m_compiler->getBytecode(_contract));
outFile.close(); outFile.close();
} }
}
if (m_args.count(g_argCloneBinaryStr))
{
if (outputToStdout(m_args[g_argCloneBinaryStr].as<OutputType>()))
{
cout << "Clone Binary: " << endl;
cout << toHex(m_compiler->getCloneBytecode(_contract)) << endl;
}
if (outputToFile(m_args[g_argCloneBinaryStr].as<OutputType>()))
{
ofstream outFile(_contract + ".clone_binary");
outFile << toHex(m_compiler->getCloneBytecode(_contract));
outFile.close();
}
}
} }
void CommandLineInterface::handleOpcode(string const& _contract) void CommandLineInterface::handleOpcode(string const& _contract)
@ -177,7 +195,7 @@ void CommandLineInterface::handleBytecode(string const& _contract)
{ {
if (m_args.count(g_argOpcodesStr)) if (m_args.count(g_argOpcodesStr))
handleOpcode(_contract); handleOpcode(_contract);
if (m_args.count(g_argBinaryStr)) if (m_args.count(g_argBinaryStr) || m_args.count(g_argCloneBinaryStr))
handleBinary(_contract); handleBinary(_contract);
} }
@ -329,6 +347,8 @@ bool CommandLineInterface::parseArguments(int argc, char** argv)
"Request to output the Opcodes of the contract.") "Request to output the Opcodes of the contract.")
(g_argBinaryStr.c_str(), po::value<OutputType>()->value_name("stdout|file|both"), (g_argBinaryStr.c_str(), po::value<OutputType>()->value_name("stdout|file|both"),
"Request to output the contract in binary (hexadecimal).") "Request to output the contract in binary (hexadecimal).")
(g_argCloneBinaryStr.c_str(), po::value<OutputType>()->value_name("stdout|file|both"),
"Request to output the clone contract in binary (hexadecimal).")
(g_argAbiStr.c_str(), po::value<OutputType>()->value_name("stdout|file|both"), (g_argAbiStr.c_str(), po::value<OutputType>()->value_name("stdout|file|both"),
"Request to output the contract's JSON ABI interface.") "Request to output the contract's JSON ABI interface.")
(g_argSolAbiStr.c_str(), po::value<OutputType>()->value_name("stdout|file|both"), (g_argSolAbiStr.c_str(), po::value<OutputType>()->value_name("stdout|file|both"),
@ -490,6 +510,8 @@ void CommandLineInterface::handleCombinedJSON()
contractData["json-abi"] = m_compiler->getInterface(contractName); contractData["json-abi"] = m_compiler->getInterface(contractName);
if (requests.count("binary")) if (requests.count("binary"))
contractData["binary"] = toHex(m_compiler->getBytecode(contractName)); contractData["binary"] = toHex(m_compiler->getBytecode(contractName));
if (requests.count("clone-binary"))
contractData["clone-binary"] = toHex(m_compiler->getCloneBytecode(contractName));
if (requests.count("opcodes")) if (requests.count("opcodes"))
contractData["opcodes"] = eth::disassemble(m_compiler->getBytecode(contractName)); contractData["opcodes"] = eth::disassemble(m_compiler->getBytecode(contractName));
if (requests.count("asm")) if (requests.count("asm"))