Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 710caf1

Browse files
author
Alan Shaw
committed
refactor: CIDv1 for block and object
License: MIT Signed-off-by: Alan Shaw <[email protected]>
1 parent 77f35ba commit 710caf1

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

src/core/components/block.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,9 @@ module.exports = function block (self) {
5656

5757
const mhtype = options.mhtype || 'sha2-256'
5858
const format = options.format || 'dag-pb'
59-
let cidVersion
59+
const cidVersion = options.version == null ? 1 : options.version
6060
// const mhlen = options.mhlen || 0
6161

62-
if (options.version == null) {
63-
// Pick appropriate CID version
64-
cidVersion = mhtype === 'sha2-256' && format === 'dag-pb' ? 0 : 1
65-
} else {
66-
cidVersion = options.version
67-
}
68-
6962
multihashing(block, mhtype, (err, multihash) => {
7063
if (err) {
7164
return cb(err)

src/core/components/object.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const dagPB = require('ipld-dag-pb')
88
const DAGNode = dagPB.DAGNode
99
const DAGLink = dagPB.DAGLink
1010
const CID = require('cids')
11-
const mh = require('multihashes')
1211
const Unixfs = require('ipfs-unixfs')
1312
const errCode = require('err-code')
1413

@@ -50,7 +49,7 @@ function parseJSONBuffer (buf, callback) {
5049
return new DAGLink(
5150
link.Name || link.name,
5251
link.Size || link.size,
53-
mh.fromB58String(link.Hash || link.hash || link.multihash)
52+
link.Hash || link.hash || link.multihash
5453
)
5554
})
5655
data = Buffer.from(parsed.Data)
@@ -88,7 +87,7 @@ module.exports = function object (self) {
8887
}
8988

9089
self._ipld.put(node, {
91-
version: 0,
90+
version: 1,
9291
hashAlg: 'sha2-256',
9392
format: 'dag-pb'
9493
}, (err, cid) => {
@@ -138,7 +137,7 @@ module.exports = function object (self) {
138137
}
139138

140139
self._ipld.put(node, {
141-
version: 0,
140+
version: 1,
142141
hashAlg: 'sha2-256',
143142
format: 'dag-pb'
144143
}, (err, cid) => {
@@ -201,7 +200,7 @@ module.exports = function object (self) {
201200

202201
function next () {
203202
self._ipld.put(node, {
204-
version: 0,
203+
version: 1,
205204
hashAlg: 'sha2-256',
206205
format: 'dag-pb'
207206
}, (err, cid) => {

0 commit comments

Comments
 (0)