Add function selector to FunctionDefinition AST JSON

This commit is contained in:
Gaith Hallak
2019-12-16 15:16:54 +03:00
parent 200747e298
commit 371e6a4801
6 changed files with 29 additions and 0 deletions
+11
View File
@@ -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;
+6
View File
@@ -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.
+4
View File
@@ -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())
+5
View File
@@ -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
+2
View File
@@ -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");