2024-05-07 19:59:27 +00:00
|
|
|
# nimbus-eth1
|
|
|
|
# Copyright (c) 2023-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/tables,
|
2024-07-18 21:32:32 +00:00
|
|
|
eth/common,
|
2024-05-07 19:59:27 +00:00
|
|
|
results,
|
|
|
|
".."/[kvt_desc, kvt_utils]
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public functions
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2024-07-18 21:32:32 +00:00
|
|
|
proc revFilter*(
|
2024-05-07 19:59:27 +00:00
|
|
|
db: KvtDbRef; # Database
|
2024-07-18 21:32:32 +00:00
|
|
|
filter: LayerRef; # Filter to revert
|
2024-10-01 21:03:10 +00:00
|
|
|
): Result[LayerRef,(seq[byte],KvtError)] =
|
2024-07-18 21:32:32 +00:00
|
|
|
## Assemble reverse filter for the `filter` argument, i.e. changes to the
|
|
|
|
## backend that reverse the effect of applying the this read-only filter.
|
2024-05-07 19:59:27 +00:00
|
|
|
##
|
2024-07-18 21:32:32 +00:00
|
|
|
## This read-only filter is calculated against the current unfiltered
|
|
|
|
## backend (excluding optionally installed read-only filter.)
|
|
|
|
##
|
|
|
|
let rev = LayerRef()
|
|
|
|
|
|
|
|
# Calculate reverse changes for the `sTab[]` structural table
|
|
|
|
for key in filter.sTab.keys:
|
|
|
|
let rc = db.getUbe key
|
|
|
|
if rc.isOk:
|
|
|
|
rev.sTab[key] = rc.value
|
|
|
|
elif rc.error == GetNotFound:
|
|
|
|
rev.sTab[key] = EmptyBlob
|
|
|
|
else:
|
|
|
|
return err((key,rc.error))
|
2024-05-07 19:59:27 +00:00
|
|
|
|
2024-07-18 21:32:32 +00:00
|
|
|
ok(rev)
|
2024-05-07 19:59:27 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# End
|
|
|
|
# ------------------------------------------------------------------------------
|