diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index d5ff7b297..0b5e046d0 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -55,6 +55,7 @@ namespace solidity // extensions and other attributes would be a better choice here? static string const g_argAbiStr = "json-abi"; static string const g_argSolAbiStr = "sol-abi"; +static string const g_argSignatureHashes = "hashes"; static string const g_argAsmStr = "asm"; static string const g_argAsmJsonStr = "asm-json"; static string const g_argAstStr = "ast"; @@ -96,6 +97,7 @@ static bool needsHumanTargetedStdout(po::variables_map const& _args) return humanTargetedStdout(_args, g_argAbiStr) || humanTargetedStdout(_args, g_argSolAbiStr) || + humanTargetedStdout(_args, g_argSignatureHashes) || humanTargetedStdout(_args, g_argNatspecUserStr) || humanTargetedStdout(_args, g_argAstJson) || humanTargetedStdout(_args, g_argNatspecDevStr) || @@ -173,6 +175,24 @@ void CommandLineInterface::handleBytecode(string const& _contract) handleBinary(_contract); } +void CommandLineInterface::handleSignatureHashes(string const& _contract) +{ + string out; + for (auto const& it: m_compiler->getContractDefinition(_contract).getInterfaceFunctions()) + out += toHex(it.first.ref()) + ": " + it.second->externalSignature() + "\n"; + + auto choice = m_args[g_argSignatureHashes].as(); + if (outputToStdout(choice)) + cout << "Function signatures: " << endl << out; + + if (outputToFile(choice)) + { + ofstream outFile(_contract + ".signatures"); + outFile << out; + outFile.close(); + } +} + void CommandLineInterface::handleMeta(DocumentationType _type, string const& _contract) { std::string argName; @@ -254,6 +274,8 @@ bool CommandLineInterface::parseArguments(int argc, char** argv) "Request to output the contract's JSON ABI interface.") (g_argSolAbiStr.c_str(), po::value()->value_name("stdout|file|both"), "Request to output the contract's Solidity ABI interface.") + (g_argSignatureHashes.c_str(), po::value()->value_name("stdout|file|both"), + "Request to output the contract's functions' signature hashes.") (g_argNatspecUserStr.c_str(), po::value()->value_name("stdout|file|both"), "Request to output the contract's Natspec user documentation.") (g_argNatspecDevStr.c_str(), po::value()->value_name("stdout|file|both"), @@ -516,6 +538,7 @@ void CommandLineInterface::actOnInput() } handleBytecode(contract); + handleSignatureHashes(contract); handleMeta(DocumentationType::ABIInterface, contract); handleMeta(DocumentationType::ABISolidityInterface, contract); handleMeta(DocumentationType::NatspecDev, contract); diff --git a/solc/CommandLineInterface.h b/solc/CommandLineInterface.h index 459f17d3e..7d3a067cd 100644 --- a/solc/CommandLineInterface.h +++ b/solc/CommandLineInterface.h @@ -58,6 +58,7 @@ private: void handleBinary(std::string const& _contract); void handleOpcode(std::string const& _contract); void handleBytecode(std::string const& _contract); + void handleSignatureHashes(std::string const& _contract); void handleMeta(DocumentationType _type, std::string const& _contract);