2018-01-16 17:05:20 +00:00
|
|
|
import
|
2018-01-17 12:57:50 +00:00
|
|
|
strformat, tables,
|
2018-02-07 16:16:04 +00:00
|
|
|
logging, constants, ttmath, errors, transaction, db/chain, utils/state, utils/header
|
2018-01-16 17:05:20 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
BaseVMState* = ref object of RootObj
|
2018-01-17 12:57:50 +00:00
|
|
|
prevHeaders*: seq[Header]
|
2018-01-24 13:31:24 +00:00
|
|
|
# receipts*:
|
2018-01-17 12:57:50 +00:00
|
|
|
chaindb*: BaseChainDB
|
2018-01-24 13:31:24 +00:00
|
|
|
# accessLogs*:
|
2018-01-17 12:57:50 +00:00
|
|
|
blockHeader*: Header
|
2018-01-16 17:05:20 +00:00
|
|
|
name*: string
|
|
|
|
|
|
|
|
proc newBaseVMState*: BaseVMState =
|
|
|
|
new(result)
|
2018-01-24 13:31:24 +00:00
|
|
|
result.prevHeaders = @[]
|
|
|
|
result.name = "BaseVM"
|
2018-01-16 17:05:20 +00:00
|
|
|
|
|
|
|
method logger*(vmState: BaseVMState): Logger =
|
2018-01-22 22:23:07 +00:00
|
|
|
logging.getLogger(&"evm.vmState.{vmState.name}")
|
|
|
|
|
2018-01-31 12:57:05 +00:00
|
|
|
method blockhash*(vmState: BaseVMState): string =
|
2018-01-22 22:23:07 +00:00
|
|
|
vmState.blockHeader.hash
|
|
|
|
|
2018-01-31 12:57:05 +00:00
|
|
|
method coinbase*(vmState: BaseVMState): string =
|
2018-01-22 22:23:07 +00:00
|
|
|
vmState.blockHeader.coinbase
|
|
|
|
|
|
|
|
method timestamp*(vmState: BaseVMState): int =
|
|
|
|
vmState.blockHeader.timestamp
|
|
|
|
|
2018-01-30 12:51:43 +00:00
|
|
|
method blockNumber*(vmState: BaseVMState): Int256 =
|
2018-01-22 22:23:07 +00:00
|
|
|
vmState.blockHeader.blockNumber
|
|
|
|
|
|
|
|
method difficulty*(vmState: BaseVMState): Int256 =
|
|
|
|
vmState.blockHeader.difficulty
|
|
|
|
|
|
|
|
method gasLimit*(vmState: BaseVMState): Int256 =
|
|
|
|
vmState.blockHeader.gasLimit
|
|
|
|
|
2018-01-31 12:57:05 +00:00
|
|
|
method getAncestorHash*(vmState: BaseVMState, blockNumber: Int256): string =
|
2018-01-22 22:23:07 +00:00
|
|
|
var ancestorDepth = vmState.blockHeader.blockNumber - blockNumber - 1.int256
|
|
|
|
if ancestorDepth >= constants.MAX_PREV_HEADER_DEPTH or
|
|
|
|
ancestorDepth < 0 or
|
|
|
|
ancestorDepth >= vmState.prevHeaders.len.int256:
|
2018-01-31 12:57:05 +00:00
|
|
|
return ""
|
2018-01-22 22:23:07 +00:00
|
|
|
var header = vmState.prevHeaders[ancestorDepth.getInt]
|
|
|
|
result = header.hash
|