2018-01-16 17:05:20 +00:00
|
|
|
import
|
2018-01-17 12:57:50 +00:00
|
|
|
strformat, tables,
|
2018-01-22 22:23:07 +00:00
|
|
|
logging, constants, bigints, 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]
|
|
|
|
receipts*: seq[string]
|
|
|
|
# computationClass*: bool
|
|
|
|
chaindb*: BaseChainDB
|
|
|
|
accessLogs*: seq[string]
|
|
|
|
blockHeader*: Header
|
2018-01-16 17:05:20 +00:00
|
|
|
name*: string
|
|
|
|
|
|
|
|
proc newBaseVMState*: BaseVMState =
|
|
|
|
new(result)
|
|
|
|
# result.chaindb = nil
|
|
|
|
# result.blockHeader = nil
|
|
|
|
# result.prevHeaders = nil
|
|
|
|
# result.computationClass = nil
|
|
|
|
# result.accessLogs = nil
|
|
|
|
# result.receipts = nil
|
|
|
|
|
|
|
|
method logger*(vmState: BaseVMState): Logger =
|
2018-01-22 22:23:07 +00:00
|
|
|
logging.getLogger(&"evm.vmState.{vmState.name}")
|
|
|
|
|
|
|
|
method blockhash*(vmState: BaseVMState): cstring =
|
|
|
|
vmState.blockHeader.hash
|
|
|
|
|
|
|
|
method coinbase*(vmState: BaseVMState): cstring =
|
|
|
|
vmState.blockHeader.coinbase
|
|
|
|
|
|
|
|
method timestamp*(vmState: BaseVMState): int =
|
|
|
|
vmState.blockHeader.timestamp
|
|
|
|
|
|
|
|
method blockBumber*(vmState: BaseVMState): Int256 =
|
|
|
|
vmState.blockHeader.blockNumber
|
|
|
|
|
|
|
|
method difficulty*(vmState: BaseVMState): Int256 =
|
|
|
|
vmState.blockHeader.difficulty
|
|
|
|
|
|
|
|
method gasLimit*(vmState: BaseVMState): Int256 =
|
|
|
|
vmState.blockHeader.gasLimit
|
|
|
|
|
|
|
|
method getAncestorHash*(vmState: BaseVMState, blockNumber: Int256): cstring =
|
|
|
|
var ancestorDepth = vmState.blockHeader.blockNumber - blockNumber - 1.int256
|
|
|
|
if ancestorDepth >= constants.MAX_PREV_HEADER_DEPTH or
|
|
|
|
ancestorDepth < 0 or
|
|
|
|
ancestorDepth >= vmState.prevHeaders.len.int256:
|
|
|
|
return cstring""
|
|
|
|
var header = vmState.prevHeaders[ancestorDepth.getInt]
|
|
|
|
result = header.hash
|