aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/interface/InterfaceHandler.cpp
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-05-10 17:54:23 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-05-19 23:11:03 +0800
commit12328b784875bad30156a2c66912652f89fa8222 (patch)
tree629e9c5ad054dae8dd83ce862d6efaeecccf7571 /libsolidity/interface/InterfaceHandler.cpp
parent4bf3cbb09a42131dba27b080a4917f30284959d3 (diff)
downloaddexon-solidity-12328b784875bad30156a2c66912652f89fa8222.tar
dexon-solidity-12328b784875bad30156a2c66912652f89fa8222.tar.gz
dexon-solidity-12328b784875bad30156a2c66912652f89fa8222.tar.bz2
dexon-solidity-12328b784875bad30156a2c66912652f89fa8222.tar.lz
dexon-solidity-12328b784875bad30156a2c66912652f89fa8222.tar.xz
dexon-solidity-12328b784875bad30156a2c66912652f89fa8222.tar.zst
dexon-solidity-12328b784875bad30156a2c66912652f89fa8222.zip
Split ABI out of InterfaceHandler
Diffstat (limited to 'libsolidity/interface/InterfaceHandler.cpp')
-rw-r--r--libsolidity/interface/InterfaceHandler.cpp115
1 files changed, 24 insertions, 91 deletions
diff --git a/libsolidity/interface/InterfaceHandler.cpp b/libsolidity/interface/InterfaceHandler.cpp
index 6c1bb0c4..b73cf46e 100644
--- a/libsolidity/interface/InterfaceHandler.cpp
+++ b/libsolidity/interface/InterfaceHandler.cpp
@@ -1,3 +1,27 @@
+/*
+ This file is part of solidity.
+
+ solidity is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ solidity is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with solidity. If not, see <http://www.gnu.org/licenses/>.
+*/
+/**
+ * @author Lefteris <lefteris@ethdev.com>
+ * @date 2014
+ * Takes the parsed AST and produces the Natspec documentation:
+ * https://github.com/ethereum/wiki/wiki/Ethereum-Natural-Specification-Format
+ *
+ * Can generally deal with JSON files
+ */
#include <libsolidity/interface/InterfaceHandler.h>
#include <boost/range/irange.hpp>
@@ -19,83 +43,11 @@ Json::Value InterfaceHandler::documentation(
return userDocumentation(_contractDef);
case DocumentationType::NatspecDev:
return devDocumentation(_contractDef);
- case DocumentationType::ABIInterface:
- return abiInterface(_contractDef);
}
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("Unknown documentation type"));
}
-Json::Value InterfaceHandler::abiInterface(ContractDefinition const& _contractDef)
-{
- Json::Value abi(Json::arrayValue);
-
- for (auto it: _contractDef.interfaceFunctions())
- {
- auto externalFunctionType = it.second->interfaceFunctionType();
- Json::Value method;
- method["type"] = "function";
- method["name"] = it.second->declaration().name();
- method["constant"] = it.second->isConstant();
- method["payable"] = it.second->isPayable();
- method["inputs"] = formatTypeList(
- externalFunctionType->parameterNames(),
- externalFunctionType->parameterTypes(),
- _contractDef.isLibrary()
- );
- method["outputs"] = formatTypeList(
- externalFunctionType->returnParameterNames(),
- externalFunctionType->returnParameterTypes(),
- _contractDef.isLibrary()
- );
- abi.append(method);
- }
- if (_contractDef.constructor())
- {
- Json::Value method;
- method["type"] = "constructor";
- auto externalFunction = FunctionType(*_contractDef.constructor(), false).interfaceFunctionType();
- solAssert(!!externalFunction, "");
- method["payable"] = externalFunction->isPayable();
- method["inputs"] = formatTypeList(
- externalFunction->parameterNames(),
- externalFunction->parameterTypes(),
- _contractDef.isLibrary()
- );
- abi.append(method);
- }
- if (_contractDef.fallbackFunction())
- {
- auto externalFunctionType = FunctionType(*_contractDef.fallbackFunction(), false).interfaceFunctionType();
- solAssert(!!externalFunctionType, "");
- Json::Value method;
- method["type"] = "fallback";
- method["payable"] = externalFunctionType->isPayable();
- abi.append(method);
- }
- for (auto const& it: _contractDef.interfaceEvents())
- {
- Json::Value event;
- event["type"] = "event";
- event["name"] = it->name();
- event["anonymous"] = it->isAnonymous();
- Json::Value params(Json::arrayValue);
- for (auto const& p: it->parameters())
- {
- solAssert(!!p->annotation().type->interfaceType(false), "");
- Json::Value input;
- input["name"] = p->name();
- input["type"] = p->annotation().type->interfaceType(false)->canonicalName(false);
- input["indexed"] = p->isIndexed();
- params.append(input);
- }
- event["inputs"] = params;
- abi.append(event);
- }
-
- return abi;
-}
-
Json::Value InterfaceHandler::userDocumentation(ContractDefinition const& _contractDef)
{
Json::Value doc;
@@ -168,25 +120,6 @@ Json::Value InterfaceHandler::devDocumentation(ContractDefinition const& _contra
return doc;
}
-Json::Value InterfaceHandler::formatTypeList(
- vector<string> const& _names,
- vector<TypePointer> const& _types,
- bool _forLibrary
-)
-{
- Json::Value params(Json::arrayValue);
- solAssert(_names.size() == _types.size(), "Names and types vector size does not match");
- for (unsigned i = 0; i < _names.size(); ++i)
- {
- solAssert(_types[i], "");
- Json::Value param;
- param["name"] = _names[i];
- param["type"] = _types[i]->canonicalName(_forLibrary);
- params.append(param);
- }
- return params;
-}
-
string InterfaceHandler::extractDoc(multimap<string, DocTag> const& _tags, string const& _name)
{
string value;