evm v0.1.14 EVM.Operation.BlockInformation
Link to this section Summary
Functions
Get the hash of one of the 256 most recent complete blocks
Get the block’s beneficiary address
Get the block’s difficulty
Get the block’s gas limit
Get the block’s number
Get the block’s timestamp
Link to this section Functions
Link to this function
blockhash(list, map)
blockhash(EVM.Operation.stack_args, EVM.Operation.vm_map) :: EVM.Operation.op_result
Get the hash of one of the 256 most recent complete blocks.
TODO: Test 256 limit
Examples
iex> block_b = %Block.Header{number: 2, mix_hash: "block_b"}
iex> block_a = %Block.Header{number: 1, mix_hash: "block_a"}
iex> genesis_block = %Block.Header{number: 0, mix_hash: <<0x00::256>>}
iex> block_map = %{<<0x00::256>> => genesis_block, "block_a" => block_a, "block_b" => block_b}
iex> block_interface = EVM.Interface.Mock.MockBlockInterface.new(block_b, block_map)
iex> exec_env = %EVM.ExecEnv{block_interface: block_interface}
iex> EVM.Operation.BlockInformation.blockhash([3], %{exec_env: exec_env})
0
iex> EVM.Operation.BlockInformation.blockhash([2], %{exec_env: exec_env})
"block_b"
iex> EVM.Operation.BlockInformation.blockhash([1], %{exec_env: exec_env})
"block_a"
iex> EVM.Operation.BlockInformation.blockhash([0], %{exec_env: exec_env})
<<0::256>>
iex> EVM.Operation.BlockInformation.blockhash([-1], %{exec_env: exec_env})
0
Link to this function
coinbase(args, map)
Get the block’s beneficiary address.
Examples
iex> block_interface = EVM.Interface.Mock.MockBlockInterface.new(%Block.Header{beneficiary: <<0x55::160>>})
iex> exec_env = %EVM.ExecEnv{block_interface: block_interface}
iex> EVM.Operation.BlockInformation.coinbase([], %{exec_env: exec_env})
<<0x55::160>>
Link to this function
difficulty(args, map)
difficulty(EVM.Operation.stack_args, EVM.Operation.vm_map) :: EVM.Operation.op_result
Get the block’s difficulty
Examples
iex> block_interface = EVM.Interface.Mock.MockBlockInterface.new(%Block.Header{difficulty: 2_000_000})
iex> exec_env = %EVM.ExecEnv{block_interface: block_interface}
iex> EVM.Operation.BlockInformation.difficulty([], %{exec_env: exec_env})
2_000_000
Link to this function
gaslimit(args, map)
Get the block’s gas limit.
Examples
iex> block_interface = EVM.Interface.Mock.MockBlockInterface.new(%Block.Header{gas_limit: 3_000_000})
iex> exec_env = %EVM.ExecEnv{block_interface: block_interface}
iex> EVM.Operation.BlockInformation.gaslimit([], %{exec_env: exec_env})
3_000_000
Link to this function
number(args, map)
Get the block’s number
Examples
iex> block_interface = EVM.Interface.Mock.MockBlockInterface.new(%Block.Header{number: 1_500_000})
iex> exec_env = %EVM.ExecEnv{block_interface: block_interface}
iex> EVM.Operation.BlockInformation.number([], %{exec_env: exec_env})
1_500_000
Link to this function
timestamp(args, map)
timestamp(EVM.Operation.stack_args, EVM.Operation.vm_map) :: EVM.Operation.op_result
Get the block’s timestamp
Examples
iex> block_interface = EVM.Interface.Mock.MockBlockInterface.new(%Block.Header{timestamp: 1_000_000})
iex> exec_env = %EVM.ExecEnv{block_interface: block_interface}
iex> EVM.Operation.BlockInformation.timestamp([], %{exec_env: exec_env})
1_000_000