Browse Source

Add blockhash to Solidity.

Autopadding fix.
cl-refactor
Gav Wood 10 years ago
parent
commit
1f7ccc48d5
  1. 2
      libdevcore/CommonJS.h
  2. 7
      libsolidity/ExpressionCompiler.cpp
  3. 4
      libsolidity/Types.cpp
  4. 2
      libsolidity/Types.h

2
libdevcore/CommonJS.h

@ -65,7 +65,7 @@ template <unsigned N> FixedHash<N> jsToFixed(std::string const& _s)
{
if (_s.substr(0, 2) == "0x")
// Hex
return FixedHash<N>(_s.substr(2));
return FixedHash<N>(_s.substr(2 + std::max<unsigned>(40, _s.size() - 2) - 40));
else if (_s.find_first_not_of("0123456789") == std::string::npos)
// Decimal
return (typename FixedHash<N>::Arith)(_s);

7
libsolidity/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:

4
libsolidity/Types.cpp

@ -656,8 +656,8 @@ MagicType::MagicType(MagicType::Kind _kind):
{
case Kind::BLOCK:
m_members = MemberList({{"coinbase", make_shared<IntegerType>(0, IntegerType::Modifier::ADDRESS)},
{"timestamp", make_shared<IntegerType >(256)},
{"prevhash", make_shared<IntegerType>(256, IntegerType::Modifier::HASH)},
{"timestamp", make_shared<IntegerType>(256)},
{"blockhash", make_shared<FunctionType>(strings{"uint"}, strings{"hash"}, FunctionType::Location::BLOCKHASH)},
{"difficulty", make_shared<IntegerType>(256)},
{"number", make_shared<IntegerType>(256)},
{"gaslimit", make_shared<IntegerType>(256)}});

2
libsolidity/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);

Loading…
Cancel
Save