Skip to content

Commit

Permalink
Use CompilerStack.contractABI directly
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed May 19, 2017
1 parent 8169e14 commit 4bf3cbb
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
7 changes: 6 additions & 1 deletion libsolidity/interface/CompilerStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,11 @@ Json::Value const& CompilerStack::contractABI(string const& _contractName) const
return metadata(_contractName, DocumentationType::ABIInterface);
}

Json::Value const& CompilerStack::contractABI(Contract const& _contract) const
{
return metadata(_contract, DocumentationType::ABIInterface);
}

Json::Value const& CompilerStack::metadata(string const& _contractName, DocumentationType _type) const
{
return metadata(contract(_contractName), _type);
Expand Down Expand Up @@ -830,7 +835,7 @@ string CompilerStack::createOnChainMetadata(Contract const& _contract) const
for (auto const& library: m_libraries)
meta["settings"]["libraries"][library.first] = "0x" + toHex(library.second.asBytes());

meta["output"]["abi"] = metadata(_contract, DocumentationType::ABIInterface);
meta["output"]["abi"] = contractABI(_contract);
meta["output"]["userdoc"] = metadata(_contract, DocumentationType::NatspecUser);
meta["output"]["devdoc"] = metadata(_contract, DocumentationType::NatspecDev);

Expand Down
2 changes: 1 addition & 1 deletion libsolidity/interface/StandardCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input)

// ABI, documentation and metadata
Json::Value contractData(Json::objectValue);
contractData["abi"] = m_compilerStack.metadata(contractName, DocumentationType::ABIInterface);
contractData["abi"] = m_compilerStack.contractABI(contractName);
contractData["metadata"] = m_compilerStack.onChainMetadata(contractName);
contractData["userdoc"] = m_compilerStack.metadata(contractName, DocumentationType::NatspecUser);
contractData["devdoc"] = m_compilerStack.metadata(contractName, DocumentationType::NatspecDev);
Expand Down
27 changes: 15 additions & 12 deletions solc/CommandLineInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,24 +266,31 @@ void CommandLineInterface::handleOnChainMetadata(string const& _contract)
return;

string data = m_compiler->onChainMetadata(_contract);
if (m_args.count("output-dir"))
if (m_args.count(g_argOutputDir))
createFile(m_compiler->filesystemFriendlyName(_contract) + "_meta.json", data);
else
cout << "Metadata: " << endl << data << endl;
}

void CommandLineInterface::handleABI(string const& _contract)
{
if (!m_args.count(g_argAbi))
return;

string data = dev::jsonCompactPrint(m_compiler->contractABI(_contract));
if (m_args.count(g_argOutputDir))
createFile(m_compiler->filesystemFriendlyName(_contract) + ".abi", data);
else
cout << "Contract JSON ABI " << endl << data << endl;
}

void CommandLineInterface::handleMeta(DocumentationType _type, string const& _contract)
{
std::string argName;
std::string suffix;
std::string title;
switch(_type)
{
case DocumentationType::ABIInterface:
argName = g_argAbi;
suffix = ".abi";
title = "Contract JSON ABI";
break;
case DocumentationType::NatspecUser:
argName = g_argNatspecUser;
suffix = ".docuser";
Expand All @@ -301,11 +308,7 @@ void CommandLineInterface::handleMeta(DocumentationType _type, string const& _co

if (m_args.count(argName))
{
std::string output;
if (_type == DocumentationType::ABIInterface)
output = dev::jsonCompactPrint(m_compiler->metadata(_contract, _type));
else
output = dev::jsonPrettyPrint(m_compiler->metadata(_contract, _type));
std::string output = dev::jsonPrettyPrint(m_compiler->metadata(_contract, _type));

if (m_args.count(g_argOutputDir))
createFile(m_compiler->filesystemFriendlyName(_contract) + suffix, output);
Expand Down Expand Up @@ -1069,7 +1072,7 @@ void CommandLineInterface::outputCompilationResults()
handleBytecode(contract);
handleSignatureHashes(contract);
handleOnChainMetadata(contract);
handleMeta(DocumentationType::ABIInterface, contract);
handleABI(contract);
handleMeta(DocumentationType::NatspecDev, contract);
handleMeta(DocumentationType::NatspecUser, contract);
} // end of contracts iteration
Expand Down
1 change: 1 addition & 0 deletions solc/CommandLineInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class CommandLineInterface
void handleBytecode(std::string const& _contract);
void handleSignatureHashes(std::string const& _contract);
void handleOnChainMetadata(std::string const& _contract);
void handleABI(std::string const& _contract);
void handleMeta(DocumentationType _type, std::string const& _contract);
void handleGasEstimation(std::string const& _contract);
void handleFormal();
Expand Down
2 changes: 1 addition & 1 deletion test/libsolidity/SolidityABIJSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class JSONInterfaceChecker
{
ETH_TEST_REQUIRE_NO_THROW(m_compilerStack.parseAndAnalyze("pragma solidity >=0.0;\n" + _code), "Parsing contract failed");

Json::Value generatedInterface = m_compilerStack.metadata("", DocumentationType::ABIInterface);
Json::Value generatedInterface = m_compilerStack.contractABI("");
Json::Value expectedInterface;
m_reader.parse(_expectedInterfaceString, expectedInterface);
BOOST_CHECK_MESSAGE(
Expand Down

0 comments on commit 4bf3cbb

Please sign in to comment.