diff --git a/AST.cpp b/AST.cpp index 59a7b61c2..2c4dbd9d6 100644 --- a/AST.cpp +++ b/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/AST.h b/AST.h index c9ad6447e..5620fa5e4 100644 --- a/AST.h +++ b/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/InterfaceHandler.cpp b/InterfaceHandler.cpp index ea787c282..d68f9dbea 100644 --- a/InterfaceHandler.cpp +++ b/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(),