From 7d7bfa1299da3123a56300cbe219ad2484ff0894 Mon Sep 17 00:00:00 2001 From: Etan Kissling Date: Mon, 7 Mar 2022 14:56:43 +0100 Subject: [PATCH] add `toBeaconBlockHeader` overload (#3468) Overloads `toBeaconBlockHeader` for `ForkedTrustedSignedBeaconBlock`. --- beacon_chain/spec/forks.nim | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/beacon_chain/spec/forks.nim b/beacon_chain/spec/forks.nim index d2697cba7..6cac15286 100644 --- a/beacon_chain/spec/forks.nim +++ b/beacon_chain/spec/forks.nim @@ -245,21 +245,6 @@ template toFork*[T: t: type T): BeaconBlockFork = BeaconBlockFork.Bellatrix -func toBeaconBlockHeader*( - blck: SomeForkyBeaconBlock): BeaconBlockHeader = - ## Reduce a given `BeaconBlock` to just its `BeaconBlockHeader`. - BeaconBlockHeader( - slot: blck.slot, - proposer_index: blck.proposer_index, - parent_root: blck.parent_root, - state_root: blck.state_root, - body_root: blck.body.hash_tree_root()) - -template toBeaconBlockHeader*( - blck: SomeForkySignedBeaconBlock): BeaconBlockHeader = - ## Reduce a given `SignedBeaconBlock` to just its `BeaconBlockHeader`. - blck.message.toBeaconBlockHeader - template init*(T: type ForkedEpochInfo, info: phase0.EpochInfo): T = T(kind: EpochInfoFork.Phase0, phase0Data: info) template init*(T: type ForkedEpochInfo, info: altair.EpochInfo): T = @@ -433,6 +418,27 @@ template withStateAndBlck*( template blck: untyped {.inject.} = b.phase0Data body +func toBeaconBlockHeader*( + blck: SomeForkyBeaconBlock): BeaconBlockHeader = + ## Reduce a given `BeaconBlock` to its `BeaconBlockHeader`. + BeaconBlockHeader( + slot: blck.slot, + proposer_index: blck.proposer_index, + parent_root: blck.parent_root, + state_root: blck.state_root, + body_root: blck.body.hash_tree_root()) + +template toBeaconBlockHeader*( + blck: SomeForkySignedBeaconBlock): BeaconBlockHeader = + ## Reduce a given `SignedBeaconBlock` to its `BeaconBlockHeader`. + blck.message.toBeaconBlockHeader + +template toBeaconBlockHeader*( + blckParam: ForkedTrustedSignedBeaconBlock): BeaconBlockHeader = + ## Reduce a given `ForkedTrustedSignedBeaconBlock` to its `BeaconBlockHeader`. + withBlck(blckParam): + blck.toBeaconBlockHeader() + func genesisFork*(cfg: RuntimeConfig): Fork = Fork( previous_version: cfg.GENESIS_FORK_VERSION,