nimbus-eth1/tests/replay/undump_helpers.nim
andri lim 5a18537450
Bump nim-eth, nim-web3, nimbus-eth2 (#2344)
* Bump nim-eth, nim-web3, nimbus-eth2

- Replace std.Option with results.Opt
- Fields name changes

* More fixes

* Fix Portal stream async raises and portal testnet Opt usage

* Bump eth + nimbus-eth2 + more fixes related to eth_types changes

* Fix in utp test app and nimbus-eth2 bump

* Fix test_blockchain_json rebase conflict

* Fix EVMC block_timestamp conversion plus commentary

---------

Co-authored-by: kdeme <kim.demey@gmail.com>
2024-06-14 14:31:08 +07:00

50 lines
1.6 KiB
Nim

# Nimbus
# Copyright (c) 2021-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
# http://www.apache.org/licenses/LICENSE-2.0)
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
# http://opensource.org/licenses/MIT)
# at your option. This file may not be copied, modified, or distributed except
# according to those terms.
import
std/sequtils,
eth/common
# ------------------------------------------------------------------------------
# Public helpers
# ------------------------------------------------------------------------------
proc startAt*(
h: openArray[EthBlock];
start: uint64;
): seq[EthBlock] =
## Filter out blocks with smaller `blockNumber`
if start.BlockNumber <= h[0].header.number:
return h.toSeq()
if start.BlockNumber <= h[^1].header.number:
# There are at least two headers, find the least acceptable one
var n = 1
while h[n].header.number < start.BlockNumber:
n.inc
return h[n ..< h.len]
proc stopAfter*(
h: openArray[EthBlock];
last: uint64;
): seq[EthBlock] =
## Filter out blocks with larger `blockNumber`
if h[^1].header.number <= last.BlockNumber:
return h.toSeq()
if h[0].header.number <= last.BlockNumber:
# There are at least two headers, find the last acceptable one
var n = 1
while h[n].header.number <= last.BlockNumber:
n.inc
return h[0 ..< n]
# ------------------------------------------------------------------------------
# End
# ------------------------------------------------------------------------------