Merge pull request #2404 from ethereum/methodidentifiers

Clean up method identifiers handling in CLI/CompilerStack
This commit is contained in:
Alex Beregszaszi 2017-06-22 13:00:19 +01:00 committed by GitHub
commit f823952d9f
5 changed files with 17 additions and 22 deletions

View File

@ -481,12 +481,12 @@ Json::Value const& CompilerStack::natspec(Contract const& _contract, Documentati
return *(*doc);
}
Json::Value CompilerStack::functionHashes(ContractDefinition const& _contract)
Json::Value CompilerStack::methodIdentifiers(string const& _contractName) const
{
Json::Value functionHashes(Json::objectValue);
for (auto const& it: _contract.interfaceFunctions())
functionHashes[it.second->externalSignature()] = toHex(it.first.ref());
return functionHashes;
Json::Value methodIdentifiers(Json::objectValue);
for (auto const& it: contractDefinition(_contractName).interfaceFunctions())
methodIdentifiers[it.second->externalSignature()] = toHex(it.first.ref());
return methodIdentifiers;
}
string const& CompilerStack::onChainMetadata(string const& _contractName) const

View File

@ -178,7 +178,8 @@ public:
/// Can be one of 4 types defined at @c DocumentationType
Json::Value const& natspec(std::string const& _contractName, DocumentationType _type) const;
Json::Value functionHashes(ContractDefinition const& _contract);
/// @returns a JSON representing a map of method identifiers (hashes) to function names.
Json::Value methodIdentifiers(std::string const& _contractName) const;
std::string const& onChainMetadata(std::string const& _contractName) const;
void useMetadataLiteralSources(bool _metadataLiteralSources) { m_metadataLiteralSources = _metadataLiteralSources; }
@ -190,9 +191,6 @@ public:
Scanner const& scanner(std::string const& _sourceName = "") const;
/// @returns the parsed source unit with the supplied name.
SourceUnit const& ast(std::string const& _sourceName = "") const;
/// @returns the parsed contract with the supplied name. Throws an exception if the contract
/// does not exist.
ContractDefinition const& contractDefinition(std::string const& _contractName) const;
/// Helper function for logs printing. Do only use in error cases, it's quite expensive.
/// line and columns are numbered starting from 1 with following order:
@ -257,6 +255,10 @@ private:
Contract const& contract(std::string const& _contractName = "") const;
Source const& source(std::string const& _sourceName = "") const;
/// @returns the parsed contract with the supplied name. Throws an exception if the contract
/// does not exist.
ContractDefinition const& contractDefinition(std::string const& _contractName) const;
std::string createOnChainMetadata(Contract const& _contract) const;
std::string computeSourceMapping(eth::AssemblyItems const& _items) const;
Json::Value const& contractABI(Contract const&) const;

View File

@ -115,14 +115,6 @@ StringMap createSourceList(Json::Value const& _input)
return sources;
}
Json::Value methodIdentifiers(ContractDefinition const& _contract)
{
Json::Value methodIdentifiers(Json::objectValue);
for (auto const& it: _contract.interfaceFunctions())
methodIdentifiers[it.second->externalSignature()] = toHex(it.first.ref());
return methodIdentifiers;
}
Json::Value formatLinkReferences(std::map<size_t, std::string> const& linkReferences)
{
Json::Value ret(Json::objectValue);
@ -404,7 +396,7 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input)
m_compilerStack.streamAssembly(tmp, contractName, createSourceList(_input), false);
evmData["assembly"] = tmp.str();
evmData["legacyAssembly"] = m_compilerStack.streamAssembly(tmp, contractName, createSourceList(_input), true);
evmData["methodIdentifiers"] = methodIdentifiers(m_compilerStack.contractDefinition(contractName));
evmData["methodIdentifiers"] = m_compilerStack.methodIdentifiers(contractName);
evmData["gasEstimates"] = m_compilerStack.gasEstimates(contractName);
evmData["bytecode"] = collectEVMObject(

View File

@ -281,9 +281,10 @@ void CommandLineInterface::handleSignatureHashes(string const& _contract)
if (!m_args.count(g_argSignatureHashes))
return;
Json::Value methodIdentifiers = m_compiler->methodIdentifiers(_contract);
string out;
for (auto const& it: m_compiler->contractDefinition(_contract).interfaceFunctions())
out += toHex(it.first.ref()) + ": " + it.second->externalSignature() + "\n";
for (auto const& name: methodIdentifiers.getMemberNames())
out += methodIdentifiers[name].asString() + ": " + name + "\n";
if (m_args.count(g_argOutputDir))
createFile(m_compiler->filesystemFriendlyName(_contract) + ".signatures", out);
@ -889,7 +890,7 @@ void CommandLineInterface::handleCombinedJSON()
contractData[g_strSrcMapRuntime] = map ? *map : "";
}
if (requests.count(g_strSignatureHashes))
contractData[g_strSignatureHashes] = m_compiler->functionHashes(m_compiler->contractDefinition(contractName));
contractData[g_strSignatureHashes] = m_compiler->methodIdentifiers(contractName);
if (requests.count(g_strNatspecDev))
contractData[g_strNatspecDev] = dev::jsonCompactPrint(m_compiler->natspec(contractName, DocumentationType::NatspecDev));
if (requests.count(g_strNatspecUser))

View File

@ -192,7 +192,7 @@ string compile(StringMap const& _sources, bool _optimize, CStyleReadFileCallback
contractData["runtimeBytecode"] = compiler.runtimeObject(contractName).toHex();
contractData["opcodes"] = solidity::disassemble(compiler.object(contractName).bytecode);
contractData["metadata"] = compiler.onChainMetadata(contractName);
contractData["functionHashes"] = compiler.functionHashes(compiler.contractDefinition(contractName));
contractData["functionHashes"] = compiler.methodIdentifiers(contractName);
contractData["gasEstimates"] = estimateGas(compiler, contractName);
auto sourceMap = compiler.sourceMapping(contractName);
contractData["srcmap"] = sourceMap ? *sourceMap : "";