Export all events.

This commit is contained in:
chriseth
2022-09-07 07:04:47 +02:00
committed by wechman
parent 548a4b4ac6
commit 049ef229c8
15 changed files with 797 additions and 5 deletions
+18 -3
View File
@@ -232,7 +232,7 @@ vector<EventDefinition const*> const& ContractDefinition::definedInterfaceEvents
vector<EventDefinition const*> const ContractDefinition::usedInterfaceEvents() const
{
solAssert(annotation().creationCallGraph.set(), "");
solAssert(annotation().creationCallGraph.set());
return util::convertContainer<std::vector<EventDefinition const*>>(
(*annotation().creationCallGraph)->emittedEvents +
@@ -240,14 +240,29 @@ vector<EventDefinition const*> const ContractDefinition::usedInterfaceEvents() c
);
}
vector<EventDefinition const*> ContractDefinition::interfaceEvents(bool _requireCallGraph) const
{
set<EventDefinition const*, CompareByID> result;
for (ContractDefinition const* contract: annotation().linearizedBaseContracts)
result += contract->events();
solAssert(annotation().creationCallGraph.set() == annotation().deployedCallGraph.set());
if (_requireCallGraph)
solAssert(annotation().creationCallGraph.set());
if (annotation().creationCallGraph.set())
result += usedInterfaceEvents();
// We could filter out all events that do not have an external interface
// if _requireCallGraph is false.
return util::convertContainer<vector<EventDefinition const*>>(std::move(result));
}
vector<ErrorDefinition const*> ContractDefinition::interfaceErrors(bool _requireCallGraph) const
{
set<ErrorDefinition const*, CompareByID> result;
for (ContractDefinition const* contract: annotation().linearizedBaseContracts)
result += filteredNodes<ErrorDefinition>(contract->m_subNodes);
solAssert(annotation().creationCallGraph.set() == annotation().deployedCallGraph.set(), "");
solAssert(annotation().creationCallGraph.set() == annotation().deployedCallGraph.set());
if (_requireCallGraph)
solAssert(annotation().creationCallGraph.set(), "");
solAssert(annotation().creationCallGraph.set());
if (annotation().creationCallGraph.set())
result +=
(*annotation().creationCallGraph)->usedErrors +
+4
View File
@@ -522,6 +522,10 @@ public:
std::vector<EventDefinition const*> events() const { return filteredNodes<EventDefinition>(m_subNodes); }
std::vector<EventDefinition const*> const& definedInterfaceEvents() const;
std::vector<EventDefinition const*> const usedInterfaceEvents() const;
/// @return all events defined in this contract and its base contracts and all events
/// that are emitted during the execution of the contract.
/// @param _requireCallGraph if false, do not fail if the call graph has not been computed yet.
std::vector<EventDefinition const*> interfaceEvents(bool _requireCallGraph = true) const;
/// @returns all errors defined in this contract or any base contract
/// and all errors referenced during execution.
/// @param _requireCallGraph if false, do not fail if the call graph has not been computed yet.
+2
View File
@@ -285,6 +285,8 @@ bool ASTJsonExporter::visit(ContractDefinition const& _node)
make_pair("abstract", _node.abstract()),
make_pair("baseContracts", toJson(_node.baseContracts())),
make_pair("contractDependencies", getContainerIds(_node.annotation().contractDependencies | ranges::views::keys)),
// Do not require call graph because the AST is also created for incorrect sources.
make_pair("emittedEvents", getContainerIds(_node.interfaceEvents(false))),
make_pair("usedErrors", getContainerIds(_node.interfaceErrors(false))),
make_pair("nodes", toJson(_node.subNodes())),
make_pair("scope", idOrNull(_node.scope()))
+1 -1
View File
@@ -101,7 +101,7 @@ Json::Value ABI::generate(ContractDefinition const& _contractDef)
method["stateMutability"] = stateMutabilityToString(externalFunctionType->stateMutability());
abi.emplace(std::move(method));
}
for (auto const& it: _contractDef.definedInterfaceEvents())
for (auto const& it: _contractDef.interfaceEvents())
{
Json::Value event{Json::objectValue};
event["type"] = "event";