2023-01-20 22:04:58 +00:00
|
|
|
# Nimbus
|
2024-02-28 17:31:45 +00:00
|
|
|
# Copyright (c) 2023-2024 Status Research & Development GmbH
|
2023-01-20 22:04:58 +00:00
|
|
|
# Licensed and distributed under either of
|
|
|
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
|
|
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
2023-01-31 12:38:08 +00:00
|
|
|
{.push raises: [].}
|
2023-01-20 22:04:58 +00:00
|
|
|
|
|
|
|
import
|
|
|
|
stew/results,
|
|
|
|
eth/common/eth_types_rlp,
|
|
|
|
../network/history/[history_content, accumulator]
|
|
|
|
|
|
|
|
export results, accumulator, history_content
|
|
|
|
|
|
|
|
proc buildHeadersWithProof*(
|
2024-02-28 17:31:45 +00:00
|
|
|
blockHeaders: seq[BlockHeader], epochAccumulator: EpochAccumulatorCached
|
|
|
|
): Result[seq[(seq[byte], seq[byte])], string] =
|
2023-01-20 22:04:58 +00:00
|
|
|
var blockHeadersWithProof: seq[(seq[byte], seq[byte])]
|
|
|
|
for header in blockHeaders:
|
|
|
|
if header.isPreMerge():
|
|
|
|
let
|
2024-02-28 17:31:45 +00:00
|
|
|
content = ?buildHeaderWithProof(header, epochAccumulator)
|
2023-01-20 22:04:58 +00:00
|
|
|
contentKey = ContentKey(
|
|
|
|
contentType: blockHeader,
|
2024-02-28 17:31:45 +00:00
|
|
|
blockHeaderKey: BlockKey(blockHash: header.blockHash()),
|
|
|
|
)
|
2023-01-20 22:04:58 +00:00
|
|
|
|
2024-02-28 17:31:45 +00:00
|
|
|
blockHeadersWithProof.add((encode(contentKey).asSeq(), SSZ.encode(content)))
|
2023-01-20 22:04:58 +00:00
|
|
|
|
2024-02-28 17:31:45 +00:00
|
|
|
ok(blockHeadersWithProof)
|