From f2502b01f7b4dd5a7611b64a070be0dcf4340aaf Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Fri, 17 Apr 2015 15:26:12 +0200 Subject: [PATCH] fixed the output of the test --- libsolidity/AST.cpp | 6 ++++++ libsolidity/AST.h | 3 +++ libsolidity/InterfaceHandler.cpp | 14 ++++++++++++-- test/libsolidity/SolidityABIJSON.cpp | 19 +++++++++---------- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/libsolidity/AST.cpp b/libsolidity/AST.cpp index 59a7b61c2..2c4dbd9d6 100644 --- a/libsolidity/AST.cpp +++ b/libsolidity/AST.cpp @@ -124,6 +124,12 @@ FunctionDefinition const* ContractDefinition::getConstructor() const return nullptr; } +FixedHash<4> ContractDefinition::getConstructorsInterface() const +{ + return FixedHash<4>(dev::sha3(getConstructor()->externalSignature())); + //return hash; +} + FunctionDefinition const* ContractDefinition::getFallbackFunction() const { for (ContractDefinition const* contract: getLinearizedBaseContracts()) diff --git a/libsolidity/AST.h b/libsolidity/AST.h index c9ad6447e..5620fa5e4 100644 --- a/libsolidity/AST.h +++ b/libsolidity/AST.h @@ -281,6 +281,9 @@ public: /// Returns the fallback function or nullptr if no fallback function was specified. FunctionDefinition const* getFallbackFunction() const; + ///@returns hash of the constructor + FixedHash<4> getConstructorsInterface() const; + private: /// Checks that two functions defined in this contract with the same name have different /// arguments and that there is at most one constructor. diff --git a/libsolidity/InterfaceHandler.cpp b/libsolidity/InterfaceHandler.cpp index ea787c282..d68f9dbea 100644 --- a/libsolidity/InterfaceHandler.cpp +++ b/libsolidity/InterfaceHandler.cpp @@ -38,7 +38,17 @@ std::unique_ptr InterfaceHandler::getDocumentation(ContractDefiniti std::unique_ptr InterfaceHandler::getABIInterface(ContractDefinition const& _contractDef) { Json::Value abi(Json::arrayValue); - for (auto const& it: _contractDef.getInterfaceFunctions()) + auto allFunctions = _contractDef.getInterfaceFunctions(); + + FunctionTypePointer functionTypePointer = nullptr; + if (_contractDef.getConstructor()) + { + functionTypePointer = make_shared(*_contractDef.getConstructor(), false); + allFunctions.insert(make_pair(_contractDef.getConstructorsInterface(), functionTypePointer)); + } + + //allFunctions.insert(_contractDef.getConstructor()); + for (auto it: allFunctions) { auto populateParameters = [](vector const& _paramNames, vector const& _paramTypes) { @@ -55,7 +65,7 @@ std::unique_ptr InterfaceHandler::getABIInterface(ContractDefinitio }; Json::Value method; - method["type"] = "function"; + method["type"] = (functionTypePointer == it.second ? "constructor" : "function"); method["name"] = it.second->getDeclaration().getName(); method["constant"] = it.second->isConstant(); method["inputs"] = populateParameters(it.second->getParameterNames(), diff --git a/test/libsolidity/SolidityABIJSON.cpp b/test/libsolidity/SolidityABIJSON.cpp index 1ba0dc7bc..de2af1d27 100644 --- a/test/libsolidity/SolidityABIJSON.cpp +++ b/test/libsolidity/SolidityABIJSON.cpp @@ -499,19 +499,18 @@ BOOST_AUTO_TEST_CASE(constructor_abi) { char const* sourceCode = R"( contract test { - function test() { + function test() { } })"; - char const* interface = R"(" - [ - { - "constant" : false, - "inputs" : [], - "name" : "test", - "outputs" : [], - "type" : "constructor" - } + char const* interface = R"([ + { + "constant" : false, + "inputs" : [], + "name" : "test", + "outputs" : [], + "type" : "constructor" + } ])"; checkInterface(sourceCode, interface); }