diff options
author | Gav Wood <g@ethdev.com> | 2015-02-01 00:29:50 +0800 |
---|---|---|
committer | Gav Wood <g@ethdev.com> | 2015-02-01 00:29:50 +0800 |
commit | bd66ebd7ee4c637c38e3e23ba6e786a66f85b677 (patch) | |
tree | c97dd72277933d3e451e6b51b3b8f39f48da451d /InterfaceHandler.cpp | |
parent | 4e440b6e5da8cb1122342377156f3706300f98c7 (diff) | |
parent | bc9d376590503956f73ee75070c74832ad97e6d2 (diff) | |
download | dexon-solidity-bd66ebd7ee4c637c38e3e23ba6e786a66f85b677.tar.gz dexon-solidity-bd66ebd7ee4c637c38e3e23ba6e786a66f85b677.tar.zst dexon-solidity-bd66ebd7ee4c637c38e3e23ba6e786a66f85b677.zip |
Merge pull request #913 from arkpar/sol_abi_fix
Fixed json ABI generation for events
Diffstat (limited to 'InterfaceHandler.cpp')
-rw-r--r-- | InterfaceHandler.cpp | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/InterfaceHandler.cpp b/InterfaceHandler.cpp index c4bed99f..7d0598ed 100644 --- a/InterfaceHandler.cpp +++ b/InterfaceHandler.cpp @@ -37,16 +37,11 @@ std::unique_ptr<std::string> InterfaceHandler::getDocumentation(ContractDefiniti std::unique_ptr<std::string> 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<string> const& _paramNames, - vector<string> const& _paramTypes) + auto populateParameters = [](vector<string> const& _paramNames, vector<string> const& _paramTypes) { Json::Value params(Json::arrayValue); solAssert(_paramNames.size() == _paramTypes.size(), "Names and types vector size does not match"); @@ -66,9 +61,27 @@ std::unique_ptr<std::string> 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<std::string>(new std::string(m_writer.write(methods))); + return std::unique_ptr<std::string>(new std::string(m_writer.write(abi))); } unique_ptr<string> InterfaceHandler::getABISolidityInterface(ContractDefinition const& _contractDef) @@ -94,6 +107,16 @@ unique_ptr<string> 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<string>(new string(ret + "}")); } |