2022-05-19 19:56:03 +00:00
|
|
|
## Nim-Codex
|
2021-02-26 00:23:22 +00:00
|
|
|
## Copyright (c) 2021 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.
|
|
|
|
|
2022-03-18 22:17:51 +00:00
|
|
|
import pkg/upraises
|
|
|
|
|
|
|
|
push: {.upraises: [].}
|
2021-08-30 19:25:20 +00:00
|
|
|
|
|
|
|
import pkg/chronos
|
|
|
|
import pkg/libp2p
|
2022-12-03 00:00:55 +00:00
|
|
|
import pkg/questionable
|
2022-01-10 15:32:56 +00:00
|
|
|
import pkg/questionable/results
|
2021-08-30 19:25:20 +00:00
|
|
|
|
2021-02-26 00:23:22 +00:00
|
|
|
import ../blocktype
|
|
|
|
|
2021-08-30 19:25:20 +00:00
|
|
|
export blocktype, libp2p
|
2021-02-26 00:23:22 +00:00
|
|
|
|
2022-12-03 00:00:55 +00:00
|
|
|
const
|
|
|
|
DefaultBlockTtl = 24.hours
|
|
|
|
|
2021-02-26 00:23:22 +00:00
|
|
|
type
|
2022-12-03 00:00:55 +00:00
|
|
|
BlockNotFoundError* = object of CodexError
|
|
|
|
|
|
|
|
BlockType* {.pure.} = enum
|
|
|
|
Manifest, Block, Both
|
|
|
|
|
|
|
|
GetNext* = proc(): Future[?Cid] {.upraises: [], gcsafe, closure.}
|
|
|
|
|
|
|
|
BlocksIter* = ref object
|
|
|
|
finished*: bool
|
|
|
|
next*: GetNext
|
|
|
|
|
2021-02-26 00:23:22 +00:00
|
|
|
BlockStore* = ref object of RootObj
|
|
|
|
|
2022-12-03 00:00:55 +00:00
|
|
|
iterator items*(self: BlocksIter): Future[?Cid] =
|
|
|
|
while not self.finished:
|
|
|
|
yield self.next()
|
|
|
|
|
2022-08-19 00:56:36 +00:00
|
|
|
method getBlock*(self: BlockStore, cid: Cid): Future[?!Block] {.base.} =
|
2022-07-28 00:39:17 +00:00
|
|
|
## Get a block from the blockstore
|
2021-02-26 00:23:22 +00:00
|
|
|
##
|
|
|
|
|
2022-03-18 22:17:51 +00:00
|
|
|
raiseAssert("Not implemented!")
|
2021-02-26 00:23:22 +00:00
|
|
|
|
2022-12-03 00:00:55 +00:00
|
|
|
method putBlock*(
|
|
|
|
self: BlockStore,
|
|
|
|
blk: Block,
|
|
|
|
ttl = Duration.none): Future[?!void] {.base.} =
|
2021-02-26 00:23:22 +00:00
|
|
|
## Put a block to the blockstore
|
|
|
|
##
|
|
|
|
|
2022-03-18 22:17:51 +00:00
|
|
|
raiseAssert("Not implemented!")
|
2021-02-26 00:23:22 +00:00
|
|
|
|
2022-07-28 00:39:17 +00:00
|
|
|
method delBlock*(self: BlockStore, cid: Cid): Future[?!void] {.base.} =
|
2022-06-28 16:10:05 +00:00
|
|
|
## Delete a block from the blockstore
|
2021-02-26 00:23:22 +00:00
|
|
|
##
|
|
|
|
|
2022-03-18 22:17:51 +00:00
|
|
|
raiseAssert("Not implemented!")
|
2021-02-26 00:23:22 +00:00
|
|
|
|
2022-07-28 00:39:17 +00:00
|
|
|
method hasBlock*(self: BlockStore, cid: Cid): Future[?!bool] {.base.} =
|
2022-01-10 15:32:56 +00:00
|
|
|
## Check if the block exists in the blockstore
|
|
|
|
##
|
|
|
|
|
2022-07-28 00:39:17 +00:00
|
|
|
raiseAssert("Not implemented!")
|
2022-01-10 15:32:56 +00:00
|
|
|
|
2022-12-03 00:00:55 +00:00
|
|
|
method listBlocks*(
|
|
|
|
self: BlockStore,
|
|
|
|
blockType = BlockType.Manifest): Future[?!BlocksIter] {.base.} =
|
2022-04-13 16:32:35 +00:00
|
|
|
## Get the list of blocks in the BlockStore. This is an intensive operation
|
|
|
|
##
|
|
|
|
|
|
|
|
raiseAssert("Not implemented!")
|
|
|
|
|
2022-07-22 23:38:49 +00:00
|
|
|
method close*(self: Blockstore): Future[void] {.base.} =
|
|
|
|
## Close the blockstore, cleaning up resources managed by it.
|
|
|
|
## For some implementations this may be a no-op
|
|
|
|
##
|
|
|
|
|
|
|
|
raiseAssert("Not implemented!")
|
|
|
|
|
2022-07-28 00:39:17 +00:00
|
|
|
proc contains*(self: BlockStore, blk: Cid): Future[bool] {.async.} =
|
|
|
|
## Check if the block exists in the blockstore.
|
|
|
|
## Return false if error encountered
|
|
|
|
##
|
|
|
|
|
|
|
|
return (await self.hasBlock(blk)) |? false
|