mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Export all events.
Update tests. Additional tests Revert changes to the Natspec
This commit is contained in:
+18
-3
@@ -220,9 +220,9 @@ vector<EventDefinition const*> const& ContractDefinition::definedInterfaceEvents
|
||||
/// NOTE: this requires the "internal" version of an Event,
|
||||
/// though here internal strictly refers to visibility,
|
||||
/// and not to function encoding (jump vs. call)
|
||||
auto const& function = e->functionType(true);
|
||||
solAssert(function, "");
|
||||
string eventSignature = function->externalSignature();
|
||||
FunctionType const* functionType = e->functionType(true);
|
||||
solAssert(functionType, "");
|
||||
string eventSignature = functionType->externalSignature();
|
||||
if (eventsSeen.count(eventSignature) == 0)
|
||||
{
|
||||
eventsSeen.insert(eventSignature);
|
||||
@@ -243,6 +243,21 @@ 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;
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -286,6 +286,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("usedEvents", getContainerIds(_node.interfaceEvents(false))),
|
||||
make_pair("usedErrors", getContainerIds(_node.interfaceErrors(false))),
|
||||
make_pair("nodes", toJson(_node.subNodes())),
|
||||
make_pair("scope", idOrNull(_node.scope()))
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -78,8 +78,16 @@ Json::Value Natspec::userDocumentation(ContractDefinition const& _contractDef)
|
||||
doc["methods"][it.second->externalSignature()]["notice"] = value;
|
||||
}
|
||||
|
||||
for (auto const& event: _contractDef.definedInterfaceEvents())
|
||||
for (auto const& event: uniqueInterfaceEvents(_contractDef))
|
||||
{
|
||||
ContractDefinition const* eventOrigin = event->annotation().contract;
|
||||
solAssert(eventOrigin);
|
||||
solAssert(
|
||||
*eventOrigin == _contractDef ||
|
||||
(!eventOrigin->isLibrary() && _contractDef.derivesFrom(*eventOrigin)) ||
|
||||
(eventOrigin->isLibrary() && !_contractDef.derivesFrom(*eventOrigin))
|
||||
);
|
||||
|
||||
string value = extractDoc(event->annotation().docTags, "notice");
|
||||
if (!value.empty())
|
||||
doc["events"][event->functionType(true)->externalSignature()]["notice"] = value;
|
||||
@@ -168,10 +176,18 @@ Json::Value Natspec::devDocumentation(ContractDefinition const& _contractDef)
|
||||
));
|
||||
}
|
||||
|
||||
for (auto const& event: _contractDef.definedInterfaceEvents())
|
||||
for (auto const& event: uniqueInterfaceEvents(_contractDef))
|
||||
if (auto devDoc = devDocumentation(event->annotation().docTags); !devDoc.empty())
|
||||
{
|
||||
ContractDefinition const* eventOrigin = event->annotation().contract;
|
||||
solAssert(eventOrigin);
|
||||
solAssert(
|
||||
*eventOrigin == _contractDef ||
|
||||
(!eventOrigin->isLibrary() && _contractDef.derivesFrom(*eventOrigin)) ||
|
||||
(eventOrigin->isLibrary() && !_contractDef.derivesFrom(*eventOrigin))
|
||||
);
|
||||
doc["events"][event->functionType(true)->externalSignature()] = devDoc;
|
||||
|
||||
}
|
||||
for (auto const& error: _contractDef.interfaceErrors())
|
||||
if (auto devDoc = devDocumentation(error->annotation().docTags); !devDoc.empty())
|
||||
doc["errors"][error->functionType(true)->externalSignature()].append(devDoc);
|
||||
@@ -255,3 +271,34 @@ Json::Value Natspec::devDocumentation(std::multimap<std::string, DocTag> const&
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
vector<EventDefinition const*> Natspec::uniqueInterfaceEvents(ContractDefinition const& _contract)
|
||||
{
|
||||
auto eventSignature = [](EventDefinition const* _event) -> string {
|
||||
FunctionType const* functionType = _event->functionType(true);
|
||||
solAssert(functionType, "");
|
||||
return functionType->externalSignature();
|
||||
};
|
||||
auto compareBySignature =
|
||||
[&](EventDefinition const* _lhs, EventDefinition const* _rhs) -> bool {
|
||||
return eventSignature(_lhs) < eventSignature(_rhs);
|
||||
};
|
||||
|
||||
set<EventDefinition const*, decltype(compareBySignature)> uniqueEvents{compareBySignature};
|
||||
// Insert events defined in the contract first so that in case of a conflict
|
||||
// they're the ones that get selected.
|
||||
uniqueEvents += _contract.definedInterfaceEvents();
|
||||
|
||||
set<EventDefinition const*, decltype(compareBySignature)> filteredUsedEvents{compareBySignature};
|
||||
set<string> usedSignatures;
|
||||
for (EventDefinition const* event: _contract.usedInterfaceEvents())
|
||||
{
|
||||
auto&& [eventIt, eventInserted] = filteredUsedEvents.insert(event);
|
||||
auto&& [signatureIt, signatureInserted] = usedSignatures.insert(eventSignature(event));
|
||||
if (!signatureInserted)
|
||||
filteredUsedEvents.erase(eventIt);
|
||||
}
|
||||
|
||||
uniqueEvents += filteredUsedEvents;
|
||||
return util::convertContainer<vector<EventDefinition const*>>(std::move(uniqueEvents));
|
||||
}
|
||||
|
||||
@@ -72,6 +72,13 @@ private:
|
||||
/// @return A JSON representation
|
||||
/// of a method's return notice documentation
|
||||
static Json::Value extractReturnParameterDocs(std::multimap<std::string, DocTag> const& _tags, std::vector<std::string> const& _returnParameterNames);
|
||||
|
||||
/// Temporary function until https://github.com/ethereum/solidity/issues/11114 is implemented.
|
||||
/// @return all events defined in the contract and its base contracts and all events
|
||||
/// that are emitted during the execution of the contract, but allowing only unique signatures.
|
||||
/// In case of conflict between a library event and a contract one, selects the latter
|
||||
/// In case of conflict between two library events, none is selected
|
||||
static std::vector<EventDefinition const*> uniqueInterfaceEvents(ContractDefinition const& _contract);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user