nimbus-eth1/nimbus/core/casper.nim

62 lines
1.9 KiB
Nim
Raw Normal View History

# 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
parentBeaconBlockRoot: Hash256
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:[].} =
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
func parentBeaconBlockRoot*(ctx: CasperRef): Hash256 =
ctx.parentBeaconBlockRoot
# ------------------------------------------------------------------------------
# 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
proc `parentBeaconBlockRoot=`*(ctx: CasperRef, val: Hash256) =
ctx.parentBeaconBlockRoot = val