Browse Source

Merge pull request #1799 from chriseth/sol_functionHashes

Feature for commandline compiler to output the function signature hashes.
cl-refactor
chriseth 10 years ago
parent
commit
202b54d575
  1. 45
      solc/CommandLineInterface.cpp
  2. 1
      solc/CommandLineInterface.h

45
solc/CommandLineInterface.cpp

@ -51,19 +51,18 @@ namespace dev
namespace solidity
{
// LTODO: Maybe some argument class pairing names with
// 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_argAsmStr = "asm";
static string const g_argAsmJsonStr = "asm-json";
static string const g_argAstStr = "ast";
static string const g_argAstJson = "ast-json";
static string const g_argBinaryStr = "binary";
static string const g_argOpcodesStr = "opcodes";
static string const g_argNatspecDevStr = "natspec-dev";
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";
static string const g_argAstJson = "ast-json";
static string const g_argBinaryStr = "binary";
static string const g_argOpcodesStr = "opcodes";
static string const g_argNatspecDevStr = "natspec-dev";
static string const g_argNatspecUserStr = "natspec-user";
static string const g_argAddStandard = "add-std";
static string const g_argAddStandard = "add-std";
/// Possible arguments to for --combined-json
static set<string> const g_combinedJsonArgs{
@ -96,6 +95,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 +173,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<OutputType>();
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 +272,8 @@ bool CommandLineInterface::parseArguments(int argc, char** argv)
"Request to output the contract's JSON ABI interface.")
(g_argSolAbiStr.c_str(), po::value<OutputType>()->value_name("stdout|file|both"),
"Request to output the contract's Solidity ABI interface.")
(g_argSignatureHashes.c_str(), po::value<OutputType>()->value_name("stdout|file|both"),
"Request to output the contract's functions' signature hashes.")
(g_argNatspecUserStr.c_str(), po::value<OutputType>()->value_name("stdout|file|both"),
"Request to output the contract's Natspec user documentation.")
(g_argNatspecDevStr.c_str(), po::value<OutputType>()->value_name("stdout|file|both"),
@ -516,6 +536,7 @@ void CommandLineInterface::actOnInput()
}
handleBytecode(contract);
handleSignatureHashes(contract);
handleMeta(DocumentationType::ABIInterface, contract);
handleMeta(DocumentationType::ABISolidityInterface, contract);
handleMeta(DocumentationType::NatspecDev, contract);

1
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);

Loading…
Cancel
Save