From d6d7c9219b66c252c64528db615faafb4ddc650c Mon Sep 17 00:00:00 2001 From: arkpar Date: Sat, 31 Jan 2015 14:41:11 +0100 Subject: json and solidity ABI generted for events --- InterfaceHandler.cpp | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) (limited to 'InterfaceHandler.cpp') diff --git a/InterfaceHandler.cpp b/InterfaceHandler.cpp index c4bed99f..e9c74fb8 100644 --- a/InterfaceHandler.cpp +++ b/InterfaceHandler.cpp @@ -37,16 +37,11 @@ std::unique_ptr InterfaceHandler::getDocumentation(ContractDefiniti std::unique_ptr InterfaceHandler::getABIInterface(ContractDefinition const& _contractDef) { - Json::Value methods(Json::arrayValue); - + Json::Value abi(Json::arrayValue); for (auto const& it: _contractDef.getInterfaceFunctions()) { Json::Value method; - Json::Value inputs(Json::arrayValue); - Json::Value outputs(Json::arrayValue); - - auto populateParameters = [](vector const& _paramNames, - vector const& _paramTypes) + auto populateParameters = [](vector const& _paramNames, vector const& _paramTypes) { Json::Value params(Json::arrayValue); solAssert(_paramNames.size() == _paramTypes.size(), "Names and types vector size does not match"); @@ -66,9 +61,28 @@ std::unique_ptr InterfaceHandler::getABIInterface(ContractDefinitio it.second->getParameterTypeNames()); method["outputs"] = populateParameters(it.second->getReturnParameterNames(), it.second->getReturnParameterTypeNames()); - methods.append(method); + abi.append(method); + } + + for (auto const& it: _contractDef.getInterfaceEvents()) + { + Json::Value event; + event["type"] = "event"; + event["name"] = it->getName(); + Json::Value params(Json::arrayValue); + for (auto const& p: it->getParameters()) + { + Json::Value input; + input["name"] = p->getName(); + input["type"] = p->getType()->toString(); + input["indexed"] = p->isIndexed(); + params.append(input); + } + event["inputs"] = params; + abi.append(event); } - return std::unique_ptr(new std::string(m_writer.write(methods))); + + return std::unique_ptr(new std::string(m_writer.write(abi))); } unique_ptr InterfaceHandler::getABISolidityInterface(ContractDefinition const& _contractDef) @@ -94,6 +108,17 @@ unique_ptr InterfaceHandler::getABISolidityInterface(ContractDefinition ret.pop_back(); ret += "{}"; } + for (auto const& it: _contractDef.getInterfaceEvents()) + { + std::string params; + for (auto const& p: it->getParameters()) + params += (params.empty() ? "(" : ",") + p->getType()->toString() + (p->isIndexed() ? " indexed " : " ") + p->getName(); + if (!params.empty()) + params += ")"; + + ret += "event " + it->getName() + params + ";"; + } + return unique_ptr(new string(ret + "}")); } -- cgit From bc9d376590503956f73ee75070c74832ad97e6d2 Mon Sep 17 00:00:00 2001 From: arkpar Date: Sat, 31 Jan 2015 14:44:04 +0100 Subject: style --- InterfaceHandler.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'InterfaceHandler.cpp') diff --git a/InterfaceHandler.cpp b/InterfaceHandler.cpp index e9c74fb8..7d0598ed 100644 --- a/InterfaceHandler.cpp +++ b/InterfaceHandler.cpp @@ -81,7 +81,6 @@ std::unique_ptr InterfaceHandler::getABIInterface(ContractDefinitio event["inputs"] = params; abi.append(event); } - return std::unique_ptr(new std::string(m_writer.write(abi))); } @@ -118,7 +117,6 @@ unique_ptr InterfaceHandler::getABISolidityInterface(ContractDefinition ret += "event " + it->getName() + params + ";"; } - return unique_ptr(new string(ret + "}")); } -- cgit