From 13dec3ac52d496906bf5661e829651684d1eb0a6 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Wed, 16 Mar 2022 15:46:44 -0600 Subject: [PATCH] make manifest a ref object --- dagger/manifest/manifest.nim | 14 +++++++------- dagger/node.nim | 2 +- dagger/stores/cachestore.nim | 3 +-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/dagger/manifest/manifest.nim b/dagger/manifest/manifest.nim index f4268d36..154c7960 100644 --- a/dagger/manifest/manifest.nim +++ b/dagger/manifest/manifest.nim @@ -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) diff --git a/dagger/node.nim b/dagger/node.nim index 13d0c876..7a7ad3ea 100644 --- a/dagger/node.nim +++ b/dagger/node.nim @@ -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 diff --git a/dagger/stores/cachestore.nim b/dagger/stores/cachestore.nim index cd5b20dd..2bf5ab58 100644 --- a/dagger/stores/cachestore.nim +++ b/dagger/stores/cachestore.nim @@ -115,8 +115,7 @@ func new*( store = CacheStore( cache: cache, currentSize: currentSize, - size: cacheSize - ) + size: cacheSize) for blk in blocks: discard store.putBlockSync(blk)