diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2017-05-07 01:02:56 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2017-05-19 22:57:36 +0800 |
commit | 4bf3cbb09a42131dba27b080a4917f30284959d3 (patch) | |
tree | 04623e38aee222c71192d42b132dc56a35fe621f | |
parent | 8169e149c98b14861cc6467f9f796010f617c521 (diff) | |
download | dexon-solidity-4bf3cbb09a42131dba27b080a4917f30284959d3.tar dexon-solidity-4bf3cbb09a42131dba27b080a4917f30284959d3.tar.gz dexon-solidity-4bf3cbb09a42131dba27b080a4917f30284959d3.tar.bz2 dexon-solidity-4bf3cbb09a42131dba27b080a4917f30284959d3.tar.lz dexon-solidity-4bf3cbb09a42131dba27b080a4917f30284959d3.tar.xz dexon-solidity-4bf3cbb09a42131dba27b080a4917f30284959d3.tar.zst dexon-solidity-4bf3cbb09a42131dba27b080a4917f30284959d3.zip |
Use CompilerStack.contractABI directly
-rw-r--r-- | libsolidity/interface/CompilerStack.cpp | 7 | ||||
-rw-r--r-- | libsolidity/interface/StandardCompiler.cpp | 2 | ||||
-rw-r--r-- | solc/CommandLineInterface.cpp | 27 | ||||
-rw-r--r-- | solc/CommandLineInterface.h | 1 | ||||
-rw-r--r-- | test/libsolidity/SolidityABIJSON.cpp | 2 |
5 files changed, 24 insertions, 15 deletions
diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 7887a2cb..1f235656 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -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); @@ -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); diff --git a/libsolidity/interface/StandardCompiler.cpp b/libsolidity/interface/StandardCompiler.cpp index 223cc15d..4eb52fc2 100644 --- a/libsolidity/interface/StandardCompiler.cpp +++ b/libsolidity/interface/StandardCompiler.cpp @@ -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); diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index badebf38..ab79aaa3 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -266,12 +266,24 @@ 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; @@ -279,11 +291,6 @@ void CommandLineInterface::handleMeta(DocumentationType _type, string const& _co 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"; @@ -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); @@ -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 diff --git a/solc/CommandLineInterface.h b/solc/CommandLineInterface.h index f52a03c7..3428532a 100644 --- a/solc/CommandLineInterface.h +++ b/solc/CommandLineInterface.h @@ -67,6 +67,7 @@ private: 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(); diff --git a/test/libsolidity/SolidityABIJSON.cpp b/test/libsolidity/SolidityABIJSON.cpp index bdcc5b10..1ebccc13 100644 --- a/test/libsolidity/SolidityABIJSON.cpp +++ b/test/libsolidity/SolidityABIJSON.cpp @@ -44,7 +44,7 @@ public: { 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( |