2025-12-18 18:23:09 +01:00
|
|
|
## Logos Storage
|
2023-03-08 16:04:54 +01:00
|
|
|
## Copyright (c) 2022 Status Research & Development GmbH
|
|
|
|
|
## Licensed under either of
|
|
|
|
|
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
|
|
|
|
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
|
|
|
|
## at your option.
|
|
|
|
|
## This file may not be copied, modified, or distributed except according to
|
|
|
|
|
## those terms.
|
|
|
|
|
|
2025-12-11 10:03:43 +01:00
|
|
|
{.push raises: [], gcsafe.}
|
2023-03-08 16:04:54 +01:00
|
|
|
|
2023-11-14 13:02:17 +01:00
|
|
|
import std/sugar
|
2023-03-08 16:04:54 +01:00
|
|
|
import pkg/questionable/results
|
|
|
|
|
import pkg/datastore
|
|
|
|
|
import pkg/libp2p
|
|
|
|
|
import ../namespaces
|
|
|
|
|
import ../manifest
|
|
|
|
|
|
|
|
|
|
const
|
2026-02-19 15:59:15 +11:00
|
|
|
StorageMetaKey* = Key.init(StorageMetaNamespace).tryGet
|
|
|
|
|
StorageRepoKey* = Key.init(StorageRepoNamespace).tryGet
|
|
|
|
|
StorageBlocksKey* = Key.init(StorageBlocksNamespace).tryGet
|
|
|
|
|
StorageTotalBlocksKey* = Key.init(StorageBlockTotalNamespace).tryGet
|
|
|
|
|
StorageManifestKey* = Key.init(StorageManifestNamespace).tryGet
|
|
|
|
|
BlocksTtlKey* = Key.init(StorageBlocksTtlNamespace).tryGet
|
|
|
|
|
BlockProofKey* = Key.init(StorageBlockProofNamespace).tryGet
|
|
|
|
|
QuotaKey* = Key.init(StorageQuotaNamespace).tryGet
|
2023-03-08 16:04:54 +01:00
|
|
|
QuotaUsedKey* = (QuotaKey / "used").tryGet
|
|
|
|
|
QuotaReservedKey* = (QuotaKey / "reserved").tryGet
|
|
|
|
|
|
|
|
|
|
func makePrefixKey*(postFixLen: int, cid: Cid): ?!Key =
|
|
|
|
|
let cidKey = ?Key.init(($cid)[^postFixLen ..^ 1] & "/" & $cid)
|
|
|
|
|
|
|
|
|
|
if ?cid.isManifest:
|
2026-02-19 15:59:15 +11:00
|
|
|
success StorageManifestKey / cidKey
|
2023-03-08 16:04:54 +01:00
|
|
|
else:
|
2026-02-19 15:59:15 +11:00
|
|
|
success StorageBlocksKey / cidKey
|
2023-03-08 16:04:54 +01:00
|
|
|
|
|
|
|
|
proc createBlockExpirationMetadataKey*(cid: Cid): ?!Key =
|
|
|
|
|
BlocksTtlKey / $cid
|
|
|
|
|
|
|
|
|
|
proc createBlockExpirationMetadataQueryKey*(): ?!Key =
|
|
|
|
|
let queryString = ?(BlocksTtlKey / "*")
|
|
|
|
|
Key.init(queryString)
|
2023-11-14 13:02:17 +01:00
|
|
|
|
|
|
|
|
proc createBlockCidAndProofMetadataKey*(treeCid: Cid, index: Natural): ?!Key =
|
|
|
|
|
(BlockProofKey / $treeCid).flatMap((k: Key) => k / $index)
|