From 911916beb7d8fd9c318d43fdf137727d364a95d2 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 15 Jan 2015 13:59:35 -0500 Subject: [PATCH] Add blockhash to Solidity. Autopadding fix. --- ExpressionCompiler.cpp | 7 +++++++ Types.cpp | 4 ++-- Types.h | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ExpressionCompiler.cpp b/ExpressionCompiler.cpp index 1c02f4f32..29338b69b 100644 --- a/ExpressionCompiler.cpp +++ b/ExpressionCompiler.cpp @@ -282,6 +282,13 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) m_context << u256(32) << u256(0) << eth::logInstruction(logNumber); break; } + case Location::BLOCKHASH: + { + arguments[0]->accept(*this); + appendTypeConversion(*arguments[0]->getType(), *function.getParameterTypes()[0], true); + m_context << eth::Instruction::BLOCKHASH; + break; + } case Location::ECRECOVER: case Location::SHA256: case Location::RIPEMD160: diff --git a/Types.cpp b/Types.cpp index 7ca1dc6d5..07d6f6bd2 100644 --- a/Types.cpp +++ b/Types.cpp @@ -656,8 +656,8 @@ MagicType::MagicType(MagicType::Kind _kind): { case Kind::BLOCK: m_members = MemberList({{"coinbase", make_shared(0, IntegerType::Modifier::ADDRESS)}, - {"timestamp", make_shared(256)}, - {"prevhash", make_shared(256, IntegerType::Modifier::HASH)}, + {"timestamp", make_shared(256)}, + {"blockhash", make_shared(strings{"uint"}, strings{"hash"}, FunctionType::Location::BLOCKHASH)}, {"difficulty", make_shared(256)}, {"number", make_shared(256)}, {"gaslimit", make_shared(256)}}); diff --git a/Types.h b/Types.h index 1ccdd706a..c011928a0 100644 --- a/Types.h +++ b/Types.h @@ -348,7 +348,7 @@ public: /// INTERNAL: jump tag, EXTERNAL: contract address + function index, /// BARE: contract address (non-abi contract call) /// OTHERS: special virtual function, nothing on the stack - enum class Location { INTERNAL, EXTERNAL, SEND, SHA3, SUICIDE, ECRECOVER, SHA256, RIPEMD160, LOG0, LOG1, LOG2, LOG3, LOG4, BARE }; + enum class Location { INTERNAL, EXTERNAL, SEND, SHA3, SUICIDE, ECRECOVER, SHA256, RIPEMD160, LOG0, LOG1, LOG2, LOG3, LOG4, BLOCKHASH, BARE }; virtual Category getCategory() const override { return Category::FUNCTION; } explicit FunctionType(FunctionDefinition const& _function, bool _isInternal = true);