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:
@@ -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