add `toBeaconBlockHeader` overload (#3468)

Overloads `toBeaconBlockHeader` for `ForkedTrustedSignedBeaconBlock`.
This commit is contained in:
Etan Kissling 2022-03-07 14:56:43 +01:00 committed by GitHub
parent 187eabeeb9
commit 7d7bfa1299
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 15 deletions

View File

@ -245,21 +245,6 @@ template toFork*[T:
t: type T): BeaconBlockFork = t: type T): BeaconBlockFork =
BeaconBlockFork.Bellatrix 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 = template init*(T: type ForkedEpochInfo, info: phase0.EpochInfo): T =
T(kind: EpochInfoFork.Phase0, phase0Data: info) T(kind: EpochInfoFork.Phase0, phase0Data: info)
template init*(T: type ForkedEpochInfo, info: altair.EpochInfo): T = template init*(T: type ForkedEpochInfo, info: altair.EpochInfo): T =
@ -433,6 +418,27 @@ template withStateAndBlck*(
template blck: untyped {.inject.} = b.phase0Data template blck: untyped {.inject.} = b.phase0Data
body 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 = func genesisFork*(cfg: RuntimeConfig): Fork =
Fork( Fork(
previous_version: cfg.GENESIS_FORK_VERSION, previous_version: cfg.GENESIS_FORK_VERSION,