2022-12-06 05:55:40 +00:00
|
|
|
# Nimbus
|
|
|
|
# Copyright (c) 2022 Status Research & Development GmbH
|
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
|
|
|
# at your option.
|
|
|
|
# This file may not be copied, modified, or distributed except according to
|
|
|
|
# those terms.
|
|
|
|
import
|
|
|
|
eth/common
|
|
|
|
|
|
|
|
type
|
|
|
|
CasperRef* = ref object
|
2023-05-22 10:55:19 +00:00
|
|
|
feeRecipient : EthAddress
|
|
|
|
timestamp : EthTime
|
|
|
|
prevRandao : Hash256
|
2023-08-30 16:29:48 +00:00
|
|
|
parentBeaconBlockRoot: Hash256
|
2022-12-06 05:55:40 +00:00
|
|
|
|
|
|
|
proc prepare*(ctx: CasperRef, header: var BlockHeader) =
|
|
|
|
header.coinbase = ctx.feeRecipient
|
|
|
|
header.timestamp = ctx.timestamp
|
|
|
|
header.prevRandao = ctx.prevRandao
|
|
|
|
header.difficulty = DifficultyInt.zero
|
|
|
|
|
2023-06-04 06:00:50 +00:00
|
|
|
proc prepareForSeal*(ctx: CasperRef, header: var BlockHeader) {.gcsafe, raises:[].} =
|
2022-12-06 05:55:40 +00:00
|
|
|
header.nonce = default(BlockNonce)
|
|
|
|
header.extraData = @[] # TODO: probably this should be configurable by user?
|
|
|
|
# this repetition, assigning prevRandao is because how txpool works
|
|
|
|
header.prevRandao = ctx.prevRandao
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Getters
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
func feeRecipient*(ctx: CasperRef): EthAddress =
|
|
|
|
ctx.feeRecipient
|
|
|
|
|
|
|
|
func timestamp*(ctx: CasperRef): EthTime =
|
|
|
|
ctx.timestamp
|
|
|
|
|
|
|
|
func prevRandao*(ctx: CasperRef): Hash256 =
|
|
|
|
ctx.prevRandao
|
|
|
|
|
2023-08-30 16:29:48 +00:00
|
|
|
func parentBeaconBlockRoot*(ctx: CasperRef): Hash256 =
|
|
|
|
ctx.parentBeaconBlockRoot
|
|
|
|
|
2022-12-06 05:55:40 +00:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Setters
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
proc `feeRecipient=`*(ctx: CasperRef, val: EthAddress) =
|
|
|
|
ctx.feeRecipient = val
|
|
|
|
|
|
|
|
proc `timestamp=`*(ctx: CasperRef, val: EthTime) =
|
|
|
|
ctx.timestamp = val
|
|
|
|
|
|
|
|
proc `prevRandao=`*(ctx: CasperRef, val: Hash256) =
|
|
|
|
ctx.prevRandao = val
|
2023-08-30 16:29:48 +00:00
|
|
|
|
|
|
|
proc `parentBeaconBlockRoot=`*(ctx: CasperRef, val: Hash256) =
|
|
|
|
ctx.parentBeaconBlockRoot = val
|