move blockstream into own dir

This commit is contained in:
Dmitriy Ryajov 2021-08-27 11:44:43 -06:00
parent 75371e9432
commit 00b5aa9c55
No known key found for this signature in database
GPG Key ID: DA8C680CE7C657A4
2 changed files with 57 additions and 0 deletions

View File

@ -0,0 +1,29 @@
## Nim-Dagger
## 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.
{.push raises: [Defect].}
import pkg/questionable
import pkg/questionable/results
import ../blocktype
export blocktype
type
BlockStreamRef* = ref object of RootObj
method nextBlock*(b: BlockStreamRef): ?!Block {.base.} =
doAssert(false, "Not implemented!")
iterator items*(b: BlockStreamRef): Block =
while true:
without blk =? b.nextBlock():
break
yield blk

View File

@ -0,0 +1,28 @@
## Nim-Dagger
## 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.
{.push raises: [Defect].}
import pkg/questionable
import pkg/questionable/results
import ./blockstream
import ./chunker
type
ChunkedBlockStreamRef* = ref object of BlockStreamRef
chunker*: Chunker
method nextBlock*(c: ChunkedBlockStreamRef): ?!Block =
let data: seq[byte] = c.chunker.getBytes()
if data.len > 0:
return success Block.new(data)
proc new*(T: type ChunkedBlockStreamRef, chunker: Chunker): T =
T(chunker: chunker)