Introduce block.chainid

This commit is contained in:
Alex Beregszaszi
2020-12-10 17:07:54 +00:00
parent d0551b67d7
commit 7cd05bf603
13 changed files with 42 additions and 2 deletions
+6
View File
@@ -2922,6 +2922,12 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess)
(memberName == "min" || memberName == "max")
)
annotation.isPure = true;
else if (magicType->kind() == MagicType::Kind::Block && memberName == "chainid" && !m_evmVersion.hasChainID())
m_errorReporter.typeError(
3081_error,
_memberAccess.location(),
"\"chainid\" is not supported by the VM version."
);
}
if (
-1
View File
@@ -368,7 +368,6 @@ void ViewPureChecker::endVisit(MemberAccess const& _memberAccess)
{MagicType::Kind::ABI, "encodePacked"},
{MagicType::Kind::ABI, "encodeWithSelector"},
{MagicType::Kind::ABI, "encodeWithSignature"},
{MagicType::Kind::Block, "blockhash"},
{MagicType::Kind::Message, "data"},
{MagicType::Kind::Message, "sig"},
{MagicType::Kind::MetaType, "creationCode"},
+2 -1
View File
@@ -3825,7 +3825,8 @@ MemberList::MemberMap MagicType::nativeMembers(ASTNode const*) const
{"blockhash", TypeProvider::function(strings{"uint"}, strings{"bytes32"}, FunctionType::Kind::BlockHash, false, StateMutability::View)},
{"difficulty", TypeProvider::uint256()},
{"number", TypeProvider::uint256()},
{"gaslimit", TypeProvider::uint256()}
{"gaslimit", TypeProvider::uint256()},
{"chainid", TypeProvider::uint256()}
});
case Kind::Message:
return MemberList::MemberMap({
@@ -1576,6 +1576,8 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
m_context << Instruction::ORIGIN;
else if (member == "gasprice")
m_context << Instruction::GASPRICE;
else if (member == "chainid")
m_context << Instruction::CHAINID;
else if (member == "data")
m_context << u256(0) << Instruction::CALLDATASIZE;
else if (member == "sig")
@@ -1688,6 +1688,8 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess)
define(_memberAccess) << "origin()\n";
else if (member == "gasprice")
define(_memberAccess) << "gasprice()\n";
else if (member == "chainid")
define(_memberAccess) << "chainid()\n";
else if (member == "data")
{
IRVariable var(_memberAccess);