Jordan Hrycaj 3ed234e0a1 clean up cyclic-import-breaker function stubs where possible for op handlers
why:
  using function stubs made it possible to check the syntax of an op
  handler source file by compiling this very file. this was previously
  impossible due cyclic import/include mechanism.

details:
  only oph_call.nim, oph_create.nim and subsequently op_handlers.nim
  still need the -d:kludge:1 flag for syntax check compiling. this flag
  also works with interpreter_dispatch.nim which imports op_handlers.nim.
2021-04-28 15:24:14 +03:00

145 lines
4.4 KiB
Nim
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Nimbus
# Copyright (c) 2018 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
# http://www.apache.org/licenses/LICENSE-2.0)
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
# http://opensource.org/licenses/MIT)
# at your option. This file may not be copied, modified, or distributed except
# according to those terms.
## EVM Opcode Handlers: Block Data
## ===============================
##
import
../../compu_helper,
../../stack,
../../v2state,
../op_codes,
./oph_defs,
eth/common,
stint,
times
# ------------------------------------------------------------------------------
# Private, op handlers implementation
# ------------------------------------------------------------------------------
const
blockhashOp: Vm2OpFn = proc (k: var Vm2Ctx) =
## 0x40, Get the hash of one of the 256 most recent complete blocks.
let (blockNumber) = k.cpt.stack.popInt(1)
k.cpt.stack.push:
k.cpt.getBlockHash(blockNumber)
coinBaseOp: Vm2OpFn = proc (k: var Vm2Ctx) =
## 0x41, Get the block's beneficiary address.
k.cpt.stack.push:
k.cpt.getCoinbase
timestampOp: Vm2OpFn = proc (k: var Vm2Ctx) =
## 0x42, Get the block's timestamp.
k.cpt.stack.push:
k.cpt.getTimestamp
blocknumberOp: Vm2OpFn = proc (k: var Vm2Ctx) =
## 0x43, Get the block's number.
k.cpt.stack.push:
k.cpt.getBlockNumber
difficultyOp: Vm2OpFn = proc (k: var Vm2Ctx) =
## 0x44, Get the block's difficulty
k.cpt.stack.push:
k.cpt.getDifficulty
gasLimitOp: Vm2OpFn = proc (k: var Vm2Ctx) =
## 0x45, Get the block's gas limit
k.cpt.stack.push:
k.cpt.getGasLimit
chainIdOp: Vm2OpFn = proc (k: var Vm2Ctx) =
## 0x46, Get current chains EIP-155 unique identifier.
k.cpt.stack.push:
k.cpt.getChainId
selfBalanceOp: Vm2OpFn = proc (k: var Vm2Ctx) =
## 0x47, Get current contract's balance.
k.cpt.stack.push:
k.cpt.getBalance(k.cpt.msg.contractAddress)
# ------------------------------------------------------------------------------
# Public, op exec table entries
# ------------------------------------------------------------------------------
const
vm2OpExecBlockData*: seq[Vm2OpExec] = @[
(opCode: Blockhash, ## 0x40, Hash of some most recent complete block
forks: Vm2OpAllForks,
name: "blockhash",
info: "Get the hash of one of the 256 most recent complete blocks",
exec: (prep: vm2OpIgnore,
run: blockhashOp,
post: vm2OpIgnore)),
(opCode: Coinbase, ## 0x41, Beneficiary address
forks: Vm2OpAllForks,
name: "coinbase",
info: "Get the block's beneficiary address",
exec: (prep: vm2OpIgnore,
run: coinBaseOp,
post: vm2OpIgnore)),
(opCode: Timestamp, ## 0x42, Block timestamp.
forks: Vm2OpAllForks,
name: "timestamp",
info: "Get the block's timestamp",
exec: (prep: vm2OpIgnore,
run: timestampOp,
post: vm2OpIgnore)),
(opCode: Number, ## 0x43, Block number
forks: Vm2OpAllForks,
name: "blockNumber",
info: "Get the block's number",
exec: (prep: vm2OpIgnore,
run: blocknumberOp,
post: vm2OpIgnore)),
(opCode: Difficulty, ## 0x44, Block difficulty
forks: Vm2OpAllForks,
name: "difficulty",
info: "Get the block's difficulty",
exec: (prep: vm2OpIgnore,
run: difficultyOp,
post: vm2OpIgnore)),
(opCode: GasLimit, ## 0x45, Block gas limit
forks: Vm2OpAllForks,
name: "gasLimit",
info: "Get the block's gas limit",
exec: (prep: vm2OpIgnore,
run: gasLimitOp,
post: vm2OpIgnore)),
(opCode: ChainId, ## 0x46, EIP-155 chain identifier
forks: Vm2OpIstanbulAndLater,
name: "chainId",
info: "Get current chains EIP-155 unique identifier",
exec: (prep: vm2OpIgnore,
run: chainIdOp,
post: vm2OpIgnore)),
(opCode: SelfBalance, ## 0x47, Contract balance.
forks: Vm2OpIstanbulAndLater,
name: "selfBalance",
info: "Get current contract's balance",
exec: (prep: vm2OpIgnore,
run: selfBalanceOp,
post: vm2OpIgnore))]
# ------------------------------------------------------------------------------
# End
# ------------------------------------------------------------------------------