Add errors to the ABI.

This commit is contained in:
chriseth
2021-02-02 12:34:58 +01:00
parent 3c69b7e552
commit 32974a5168
3 changed files with 109 additions and 0 deletions
+20
View File
@@ -121,6 +121,26 @@ Json::Value ABI::generate(ContractDefinition const& _contractDef)
abi.emplace(std::move(event));
}
// TODO should use "used errors" once implemented,
// but should also include all errors defined in the contract.
for (ErrorDefinition const* error: _contractDef.errors())
{
Json::Value event;
event["type"] = "error";
event["name"] = error->name();
Json::Value params(Json::arrayValue);
for (auto const& p: error->parameters())
{
Type const* type = p->annotation().type->interfaceType(false);
solAssert(type, "");
Json::Value input;
auto param = formatType(p->name(), *type, *p->annotation().type, false);
params.append(std::move(param));
}
event["inputs"] = std::move(params);
abi.emplace(std::move(event));
}
Json::Value abiJson{Json::arrayValue};
for (auto& f: abi)
abiJson.append(std::move(f));