make manifest a ref object

This commit is contained in:
Dmitriy Ryajov 2022-03-16 15:46:44 -06:00
parent f2aa945991
commit 13dec3ac52
No known key found for this signature in database
GPG Key ID: DA8C680CE7C657A4
3 changed files with 9 additions and 10 deletions

View File

@ -45,7 +45,7 @@ template EmptyDigests: untyped =
emptyDigests
type
Manifest* = object of RootObj
Manifest* = ref object of RootObj
rootHash*: ?Cid # root (tree) hash of the contained data set
blockSize*: int # size of each contained block (might not be needed if blocks are len-prefixed)
blocks*: seq[Cid] # block Cid
@ -69,11 +69,11 @@ func `[]=`*(self: var Manifest, i: Natural, item: Cid) =
func `[]`*(self: Manifest, i: BackwardsIndex): Cid =
self.blocks[self.len - i.int]
func `[]=`*(self: var Manifest, i: BackwardsIndex, item: Cid) =
func `[]=`*(self: Manifest, i: BackwardsIndex, item: Cid) =
self.rootHash = Cid.none
self.blocks[self.len - i.int] = item
proc add*(self: var Manifest, cid: Cid) =
proc add*(self: Manifest, cid: Cid) =
self.rootHash = Cid.none
trace "Adding cid to manifest", cid
self.blocks.add(cid)
@ -91,7 +91,7 @@ template hashBytes(mh: MultiHash): seq[byte] =
mh.data.buffer[mh.dpos..(mh.dpos + mh.size - 1)]
proc makeRoot*(self: var Manifest): ?!void =
proc makeRoot*(self: Manifest): ?!void =
## Create a tree hash root of the contained
## block hashes
##
@ -122,7 +122,7 @@ proc makeRoot*(self: var Manifest): ?!void =
ok()
proc cid*(self: var Manifest): ?!Cid =
proc cid*(self: Manifest): ?!Cid =
## Generate a root hash using the treehash algorithm
##
@ -131,7 +131,7 @@ proc cid*(self: var Manifest): ?!Cid =
(!self.rootHash).success
proc init*(
proc new*(
T: type Manifest,
blocks: openArray[Cid] = [],
version = CIDv1,
@ -152,7 +152,7 @@ proc init*(
blockSize: blockSize
).success
proc init*(
proc new*(
T: type Manifest,
data: openArray[byte]): ?!T =
Manifest.decode(data)

View File

@ -118,7 +118,7 @@ proc store*(
stream: LPStream): Future[?!Cid] {.async.} =
trace "Storing data"
without var blockManifest =? Manifest.init():
without var blockManifest =? Manifest.new():
return failure("Unable to create Block Set")
let

View File

@ -115,8 +115,7 @@ func new*(
store = CacheStore(
cache: cache,
currentSize: currentSize,
size: cacheSize
)
size: cacheSize)
for blk in blocks:
discard store.putBlockSync(blk)