mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Add ContractDefinition::interfaceId() helper
This commit is contained in:
parent
83934254ea
commit
9aa9962f71
@ -208,6 +208,14 @@ vector<pair<util::FixedHash<4>, FunctionTypePointer>> const& ContractDefinition:
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t ContractDefinition::interfaceId() const
|
||||||
|
{
|
||||||
|
uint64_t result{0};
|
||||||
|
for (auto const& function: interfaceFunctionList(false))
|
||||||
|
result ^= util::fromBigEndian<uint64_t>(function.first.ref());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
TypePointer ContractDefinition::type() const
|
TypePointer ContractDefinition::type() const
|
||||||
{
|
{
|
||||||
return TypeProvider::typeType(TypeProvider::contract(*this));
|
return TypeProvider::typeType(TypeProvider::contract(*this));
|
||||||
|
@ -509,6 +509,8 @@ public:
|
|||||||
/// as intended for use by the ABI.
|
/// as intended for use by the ABI.
|
||||||
std::map<util::FixedHash<4>, FunctionTypePointer> interfaceFunctions(bool _includeInheritedFunctions = true) const;
|
std::map<util::FixedHash<4>, FunctionTypePointer> interfaceFunctions(bool _includeInheritedFunctions = true) const;
|
||||||
std::vector<std::pair<util::FixedHash<4>, FunctionTypePointer>> const& interfaceFunctionList(bool _includeInheritedFunctions = true) const;
|
std::vector<std::pair<util::FixedHash<4>, FunctionTypePointer>> const& interfaceFunctionList(bool _includeInheritedFunctions = true) const;
|
||||||
|
/// @returns the EIP-165 compatible interface identifier. This will exclude inherited functions.
|
||||||
|
uint64_t interfaceId() const;
|
||||||
|
|
||||||
/// @returns a list of all declarations in this contract
|
/// @returns a list of all declarations in this contract
|
||||||
std::vector<Declaration const*> declarations() const { return filteredNodes<Declaration>(m_subNodes); }
|
std::vector<Declaration const*> declarations() const { return filteredNodes<Declaration>(m_subNodes); }
|
||||||
|
@ -1598,10 +1598,7 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
|
|||||||
{
|
{
|
||||||
TypePointer arg = dynamic_cast<MagicType const&>(*_memberAccess.expression().annotation().type).typeArgument();
|
TypePointer arg = dynamic_cast<MagicType const&>(*_memberAccess.expression().annotation().type).typeArgument();
|
||||||
ContractDefinition const& contract = dynamic_cast<ContractType const&>(*arg).contractDefinition();
|
ContractDefinition const& contract = dynamic_cast<ContractType const&>(*arg).contractDefinition();
|
||||||
uint64_t result{0};
|
m_context << (u256{contract.interfaceId()} << (256 - 32));
|
||||||
for (auto const& function: contract.interfaceFunctionList(false))
|
|
||||||
result ^= fromBigEndian<uint64_t>(function.first.ref());
|
|
||||||
m_context << (u256{result} << (256 - 32));
|
|
||||||
}
|
}
|
||||||
else if (member == "min" || member == "max")
|
else if (member == "min" || member == "max")
|
||||||
{
|
{
|
||||||
|
@ -1549,10 +1549,7 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess)
|
|||||||
{
|
{
|
||||||
TypePointer arg = dynamic_cast<MagicType const&>(*_memberAccess.expression().annotation().type).typeArgument();
|
TypePointer arg = dynamic_cast<MagicType const&>(*_memberAccess.expression().annotation().type).typeArgument();
|
||||||
ContractDefinition const& contract = dynamic_cast<ContractType const&>(*arg).contractDefinition();
|
ContractDefinition const& contract = dynamic_cast<ContractType const&>(*arg).contractDefinition();
|
||||||
uint64_t result{0};
|
define(_memberAccess) << formatNumber(u256{contract.interfaceId()} << (256 - 32)) << "\n";
|
||||||
for (auto const& function: contract.interfaceFunctionList(false))
|
|
||||||
result ^= fromBigEndian<uint64_t>(function.first.ref());
|
|
||||||
define(_memberAccess) << formatNumber(u256{result} << (256 - 32)) << "\n";
|
|
||||||
}
|
}
|
||||||
else if (member == "min" || member == "max")
|
else if (member == "min" || member == "max")
|
||||||
{
|
{
|
||||||
|
@ -890,12 +890,8 @@ bool SMTEncoder::visit(MemberAccess const& _memberAccess)
|
|||||||
}
|
}
|
||||||
else if (memberName == "interfaceId")
|
else if (memberName == "interfaceId")
|
||||||
{
|
{
|
||||||
// TODO: move this calculation into ContractDefinition and share with ExpressionCompiler
|
|
||||||
ContractDefinition const& contract = dynamic_cast<ContractType const&>(*magicType->typeArgument()).contractDefinition();
|
ContractDefinition const& contract = dynamic_cast<ContractType const&>(*magicType->typeArgument()).contractDefinition();
|
||||||
uint64_t result{0};
|
defineExpr(_memberAccess, contract.interfaceId());
|
||||||
for (auto const& function: contract.interfaceFunctionList(false))
|
|
||||||
result ^= fromBigEndian<uint64_t>(function.first.ref());
|
|
||||||
defineExpr(_memberAccess, result);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
// NOTE: supporting name, creationCode, runtimeCode would be easy enough, but the bytes/string they return are not
|
// NOTE: supporting name, creationCode, runtimeCode would be easy enough, but the bytes/string they return are not
|
||||||
|
Loading…
Reference in New Issue
Block a user