mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Add function selector to FunctionDefinition AST JSON
This commit is contained in:
parent
200747e298
commit
371e6a4801
@ -38,6 +38,7 @@ Language Features:
|
||||
* Introduce ``virtual`` and ``override`` keywords.
|
||||
* Modify ``push(element)`` for dynamic storage arrays such that it does not return the new length anymore.
|
||||
* Yul: Introduce ``leave`` statement that exits the current function.
|
||||
* JSON AST: Add the function selector of each externally-visible FunctonDefinition to the AST JSON export.
|
||||
|
||||
Compiler Features:
|
||||
* Allow revert strings to be stripped from the binary using the ``--revert-strings`` option or the ``settings.debug.revertStrings`` setting.
|
||||
|
@ -368,6 +368,11 @@ string FunctionDefinition::externalSignature() const
|
||||
return TypeProvider::function(*this)->externalSignature();
|
||||
}
|
||||
|
||||
string FunctionDefinition::externalIdentifierHex() const
|
||||
{
|
||||
return TypeProvider::function(*this)->externalIdentifierHex();
|
||||
}
|
||||
|
||||
FunctionDefinitionAnnotation& FunctionDefinition::annotation() const
|
||||
{
|
||||
if (!m_annotation)
|
||||
@ -596,6 +601,12 @@ set<VariableDeclaration::Location> VariableDeclaration::allowedDataLocations() c
|
||||
return set<Location>{ Location::Unspecified };
|
||||
}
|
||||
|
||||
string VariableDeclaration::externalIdentifierHex() const
|
||||
{
|
||||
solAssert(isStateVariable() && isPublic(), "Can only be called for public state variables");
|
||||
return TypeProvider::function(*this)->externalIdentifierHex();
|
||||
}
|
||||
|
||||
TypePointer VariableDeclaration::type() const
|
||||
{
|
||||
return annotation().type;
|
||||
|
@ -708,6 +708,9 @@ public:
|
||||
/// arguments separated by commas all enclosed in parentheses without any spaces.
|
||||
std::string externalSignature() const;
|
||||
|
||||
/// @returns the external identifier of this function (the hash of the signature) as a hex string.
|
||||
std::string externalIdentifierHex() const;
|
||||
|
||||
ContractDefinition::ContractKind inContractKind() const;
|
||||
|
||||
TypePointer type() const override;
|
||||
@ -807,6 +810,9 @@ public:
|
||||
/// @returns a set of allowed storage locations for the variable.
|
||||
std::set<Location> allowedDataLocations() const;
|
||||
|
||||
/// @returns the external identifier of this variable (the hash of the signature) as a hex string (works only for public state variables).
|
||||
std::string externalIdentifierHex() const;
|
||||
|
||||
TypePointer type() const override;
|
||||
|
||||
/// @param _internal false indicates external interface is concerned, true indicates internal interface is concerned.
|
||||
|
@ -362,6 +362,8 @@ bool ASTJsonConverter::visit(FunctionDefinition const& _node)
|
||||
make_pair("implemented", _node.isImplemented()),
|
||||
make_pair("scope", idOrNull(_node.scope()))
|
||||
};
|
||||
if (_node.isPartOfExternalInterface())
|
||||
attributes.emplace_back("functionSelector", _node.externalIdentifierHex());
|
||||
if (!_node.annotation().baseFunctions.empty())
|
||||
attributes.emplace_back(make_pair("baseFunctions", getContainerIds(_node.annotation().baseFunctions, true)));
|
||||
if (m_legacy)
|
||||
@ -384,6 +386,8 @@ bool ASTJsonConverter::visit(VariableDeclaration const& _node)
|
||||
make_pair("scope", idOrNull(_node.scope())),
|
||||
make_pair("typeDescriptions", typePointerToJson(_node.annotation().type, true))
|
||||
};
|
||||
if (_node.isStateVariable() && _node.isPublic())
|
||||
attributes.emplace_back("functionSelector", _node.externalIdentifierHex());
|
||||
if (m_inEvent)
|
||||
attributes.emplace_back("indexed", _node.isIndexed());
|
||||
if (!_node.annotation().baseFunctions.empty())
|
||||
|
@ -3191,6 +3191,11 @@ u256 FunctionType::externalIdentifier() const
|
||||
return FixedHash<4>::Arith(FixedHash<4>(dev::keccak256(externalSignature())));
|
||||
}
|
||||
|
||||
string FunctionType::externalIdentifierHex() const
|
||||
{
|
||||
return FixedHash<4>(dev::keccak256(externalSignature())).hex();
|
||||
}
|
||||
|
||||
bool FunctionType::isPure() const
|
||||
{
|
||||
// TODO: replace this with m_stateMutability == StateMutability::Pure once
|
||||
|
@ -1190,6 +1190,8 @@ public:
|
||||
std::string externalSignature() const;
|
||||
/// @returns the external identifier of this function (the hash of the signature).
|
||||
u256 externalIdentifier() const;
|
||||
/// @returns the external identifier of this function (the hash of the signature) as a hex string.
|
||||
std::string externalIdentifierHex() const;
|
||||
Declaration const& declaration() const
|
||||
{
|
||||
solAssert(m_declaration, "Requested declaration from a FunctionType that has none");
|
||||
|
Loading…
Reference in New Issue
Block a user