aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbitshift <bitshift@posteo.org>2018-03-06 02:23:49 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2018-03-27 10:30:03 +0800
commited632025fe5995d093472b1e7660087e943f2ca6 (patch)
treedef99c82a8fe0e5b7546637354ad49129cd9dceb
parentba209fe485ba40ea3926800bc90932bec40cd16f (diff)
downloaddexon-solidity-ed632025fe5995d093472b1e7660087e943f2ca6.tar.gz
dexon-solidity-ed632025fe5995d093472b1e7660087e943f2ca6.tar.zst
dexon-solidity-ed632025fe5995d093472b1e7660087e943f2ca6.zip
Moves blockhash function to global level.
-rw-r--r--libsolidity/analysis/GlobalContext.cpp1
-rw-r--r--libsolidity/ast/Types.cpp29
2 files changed, 21 insertions, 9 deletions
diff --git a/libsolidity/analysis/GlobalContext.cpp b/libsolidity/analysis/GlobalContext.cpp
index 34cb61d8..6a858d36 100644
--- a/libsolidity/analysis/GlobalContext.cpp
+++ b/libsolidity/analysis/GlobalContext.cpp
@@ -38,6 +38,7 @@ m_magicVariables(vector<shared_ptr<MagicVariableDeclaration const>>{
make_shared<MagicVariableDeclaration>("addmod", make_shared<FunctionType>(strings{"uint256", "uint256", "uint256"}, strings{"uint256"}, FunctionType::Kind::AddMod, false, StateMutability::Pure)),
make_shared<MagicVariableDeclaration>("assert", make_shared<FunctionType>(strings{"bool"}, strings{}, FunctionType::Kind::Assert, false, StateMutability::Pure)),
make_shared<MagicVariableDeclaration>("block", make_shared<MagicType>(MagicType::Kind::Block)),
+ make_shared<MagicVariableDeclaration>("blockhash", make_shared<FunctionType>(strings{"uint256"}, strings{"bytes32"}, FunctionType::Kind::BlockHash, false, StateMutability::View)),
make_shared<MagicVariableDeclaration>("ecrecover", make_shared<FunctionType>(strings{"bytes32", "uint8", "bytes32", "bytes32"}, strings{"address"}, FunctionType::Kind::ECRecover, false, StateMutability::Pure)),
make_shared<MagicVariableDeclaration>("gasleft", make_shared<FunctionType>(strings(), strings{"uint256"}, FunctionType::Kind::GasLeft, false, StateMutability::View)),
make_shared<MagicVariableDeclaration>("keccak256", make_shared<FunctionType>(strings(), strings{"bytes32"}, FunctionType::Kind::SHA3, true, StateMutability::Pure)),
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp
index 41700e28..f4559eda 100644
--- a/libsolidity/ast/Types.cpp
+++ b/libsolidity/ast/Types.cpp
@@ -3002,19 +3002,30 @@ bool MagicType::operator==(Type const& _other) const
return other.m_kind == m_kind;
}
-MemberList::MemberMap MagicType::nativeMembers(ContractDefinition const*) const
+MemberList::MemberMap MagicType::nativeMembers(ContractDefinition const* _contract) const
{
+ const bool v050 = _contract->sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050);
switch (m_kind)
{
case Kind::Block:
- return MemberList::MemberMap({
- {"coinbase", make_shared<IntegerType>(160, IntegerType::Modifier::Address)},
- {"timestamp", make_shared<IntegerType>(256)},
- {"blockhash", make_shared<FunctionType>(strings{"uint"}, strings{"bytes32"}, FunctionType::Kind::BlockHash, false, StateMutability::View)},
- {"difficulty", make_shared<IntegerType>(256)},
- {"number", make_shared<IntegerType>(256)},
- {"gaslimit", make_shared<IntegerType>(256)}
- });
+ {
+ std::vector<MemberList::Member> members = {
+ {"coinbase", make_shared<IntegerType>(160, IntegerType::Modifier::Address)},
+ {"timestamp", make_shared<IntegerType>(256)},
+ {"difficulty", make_shared<IntegerType>(256)},
+ {"number", make_shared<IntegerType>(256)},
+ {"gaslimit", make_shared<IntegerType>(256)}
+ };
+
+ if (!v050)
+ {
+ auto blockhashFun = make_shared<FunctionType>(strings{"uint256"}, strings{"bytes32"},
+ FunctionType::Kind::BlockHash, false, StateMutability::View);
+
+ members.emplace_back("blockhash", blockhashFun);
+ }
+ return MemberList::MemberMap(members);
+ }
case Kind::Message:
return MemberList::MemberMap({
{"sender", make_shared<IntegerType>(160, IntegerType::Modifier::Address)},