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

Commit 2b5edc5

Browse files
committed
fix: updates ipld-dag-pb dep to version without .cid properties
Follows on from ipld/js-ipld-dag-pb#99 and updates this module to not rely on DAGNodes having knowledge of their CIDs.
1 parent 74edafd commit 2b5edc5

File tree

18 files changed

+360
-243
lines changed

18 files changed

+360
-243
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"execa": "^1.0.0",
6969
"form-data": "^2.3.3",
7070
"hat": "0.0.3",
71-
"interface-ipfs-core": "~0.83.0",
71+
"interface-ipfs-core": "ipfs/interface-ipfs-core#update-dag-pb-to-not-have-cid-property",
7272
"ipfsd-ctl": "~0.39.5",
7373
"ncp": "^2.0.0",
7474
"qs": "^6.5.2",
@@ -98,7 +98,7 @@
9898
"hoek": "^5.0.4",
9999
"human-to-milliseconds": "^1.0.0",
100100
"interface-datastore": "~0.6.0",
101-
"ipfs-api": "^26.0.3",
101+
"ipfs-api": "ipfs/js-ipfs-api#update-dag-pb-to-not-have-cid-property",
102102
"ipfs-bitswap": "~0.21.0",
103103
"ipfs-block": "~0.8.0",
104104
"ipfs-block-service": "~0.15.1",
@@ -108,10 +108,10 @@
108108
"ipfs-repo": "~0.25.0",
109109
"ipfs-unixfs": "~0.1.16",
110110
"ipfs-unixfs-engine": "~0.33.0",
111-
"ipld-dag-pb": "~0.14.11",
112111
"ipns": "~0.3.0",
113-
"ipld": "~0.19.1",
112+
"ipld": "ipld/js-ipld#depend-on-dag-pb-without-cid",
114113
"ipld-bitcoin": "~0.1.8",
114+
"ipld-dag-pb": "ipld/js-ipld-dag-pb#remove-cid-property-from-dagnodes",
115115
"ipld-ethereum": "^2.0.1",
116116
"ipld-git": "~0.2.2",
117117
"ipld-raw": "^2.0.1",

src/cli/commands/object/links.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = {
2020
links.forEach((link) => {
2121
link = link.toJSON()
2222

23-
print(`${link.multihash} ${link.size} ${link.name}`)
23+
print(`${link.cid} ${link.size} ${link.name}`)
2424
})
2525
})
2626
}

src/cli/commands/object/new.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ const debug = require('debug')
44
const log = debug('cli:object')
55
log.error = debug('cli:object:error')
66
const print = require('../../utils').print
7+
const {
8+
util: {
9+
cid
10+
}
11+
} = require('ipld-dag-pb')
712

813
module.exports = {
914
command: 'new [<template>]',
@@ -18,9 +23,13 @@ module.exports = {
1823
throw err
1924
}
2025

21-
const nodeJSON = node.toJSON()
26+
cid(node, (err, cid) => {
27+
if (err) {
28+
throw err
29+
}
2230

23-
print(nodeJSON.multihash)
31+
print(cid.toBaseEncodedString())
32+
})
2433
})
2534
}
2635
}

src/cli/commands/object/patch/add-link.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
const dagPB = require('ipld-dag-pb')
44
const DAGLink = dagPB.DAGLink
55
const print = require('../../../utils').print
6+
const {
7+
util: {
8+
cid
9+
}
10+
} = require('ipld-dag-pb')
611

712
module.exports = {
813
command: 'add-link <root> <name> <ref>',
@@ -20,16 +25,28 @@ module.exports = {
2025
throw err
2126
}
2227

23-
const link = new DAGLink(argv.name, nodeA.size, nodeA.multihash)
24-
25-
ipfs.object.patch.addLink(argv.root, link, {
26-
enc: 'base58'
27-
}, (err, nodeB) => {
28+
cid(nodeA, (err, result) => {
2829
if (err) {
2930
throw err
3031
}
3132

32-
print(nodeB.toJSON().multihash)
33+
const link = new DAGLink(argv.name, nodeA.size, result)
34+
35+
ipfs.object.patch.addLink(argv.root, link, {
36+
enc: 'base58'
37+
}, (err, nodeB) => {
38+
if (err) {
39+
throw err
40+
}
41+
42+
cid(nodeB, (err, result) => {
43+
if (err) {
44+
throw err
45+
}
46+
47+
print(result.toBaseEncodedString())
48+
})
49+
})
3350
})
3451
})
3552
}

src/cli/commands/object/patch/append-data.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ const debug = require('debug')
66
const log = debug('cli:object')
77
log.error = debug('cli:object:error')
88
const print = require('../../../utils').print
9+
const {
10+
util: {
11+
cid
12+
}
13+
} = require('ipld-dag-pb')
914

1015
function appendData (key, data, ipfs) {
1116
ipfs.object.patch.appendData(key, data, {
@@ -14,9 +19,14 @@ function appendData (key, data, ipfs) {
1419
if (err) {
1520
throw err
1621
}
17-
const nodeJSON = node.toJSON()
1822

19-
print(nodeJSON.multihash)
23+
cid(node, (err, cid) => {
24+
if (err) {
25+
throw err
26+
}
27+
28+
print(cid.toBaseEncodedString())
29+
})
2030
})
2131
}
2232

src/cli/commands/object/patch/rm-link.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ const debug = require('debug')
44
const log = debug('cli:object')
55
log.error = debug('cli:object:error')
66
const print = require('../../../utils').print
7+
const {
8+
util: {
9+
cid
10+
}
11+
} = require('ipld-dag-pb')
712

813
module.exports = {
914
command: 'rm-link <root> <link>',
@@ -20,9 +25,13 @@ module.exports = {
2025
throw err
2126
}
2227

23-
const nodeJSON = node.toJSON()
28+
cid(node, (err, cid) => {
29+
if (err) {
30+
throw err
31+
}
2432

25-
print(nodeJSON.multihash)
33+
print(cid.toBaseEncodedString())
34+
})
2635
})
2736
}
2837
}

src/cli/commands/object/patch/set-data.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ const debug = require('debug')
66
const log = debug('cli:object')
77
log.error = debug('cli:object:error')
88
const print = require('../../../utils').print
9+
const {
10+
util: {
11+
cid
12+
}
13+
} = require('ipld-dag-pb')
914

1015
function parseAndAddNode (key, data, ipfs) {
1116
ipfs.object.patch.setData(key, data, {
@@ -14,9 +19,14 @@ function parseAndAddNode (key, data, ipfs) {
1419
if (err) {
1520
throw err
1621
}
17-
const nodeJSON = node.toJSON()
1822

19-
print(nodeJSON.multihash)
23+
cid(node, (err, cid) => {
24+
if (err) {
25+
throw err
26+
}
27+
28+
print(cid.toBaseEncodedString())
29+
})
2030
})
2131
}
2232

src/cli/commands/object/put.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,25 @@
33
const bl = require('bl')
44
const fs = require('fs')
55
const print = require('../../utils').print
6+
const {
7+
util: {
8+
cid
9+
}
10+
} = require('ipld-dag-pb')
611

712
function putNode (buf, enc, ipfs) {
813
ipfs.object.put(buf, {enc: enc}, (err, node) => {
914
if (err) {
1015
throw err
1116
}
1217

13-
const nodeJSON = node.toJSON()
18+
cid(node, (err, cid) => {
19+
if (err) {
20+
throw err
21+
}
1422

15-
print(`added ${nodeJSON.multihash}`)
23+
print(`added ${cid.toBaseEncodedString()}`)
24+
})
1625
})
1726
}
1827

src/cli/utils.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,6 @@ const Progress = require('progress')
1111
const byteman = require('byteman')
1212
const promisify = require('promisify-es6')
1313

14-
// All known IPLD formats
15-
const ipldBitcoin = require('ipld-bitcoin')
16-
const ipldDagCbor = require('ipld-dag-cbor')
17-
const ipldDagPb = require('ipld-dag-pb')
18-
const ipldEthAccountSnapshot = require('ipld-ethereum').ethAccountSnapshot
19-
const ipldEthBlock = require('ipld-ethereum').ethBlock
20-
const ipldEthBlockList = require('ipld-ethereum').ethBlockList
21-
const ipldEthStateTrie = require('ipld-ethereum').ethStateTrie
22-
const ipldEthStorageTrie = require('ipld-ethereum').ethStorageTrie
23-
const ipldEthTrie = require('ipld-ethereum').ethTxTrie
24-
const ipldEthTx = require('ipld-ethereum').ethTx
25-
const ipldGit = require('ipld-git')
26-
const ipldRaw = require('ipld-raw')
27-
const ipldZcash = require('ipld-zcash')
28-
2914
exports = module.exports
3015

3116
exports.isDaemonOn = isDaemonOn

src/core/components/dag.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ module.exports = function dag (self) {
156156
if (err) { return callback(err) }
157157

158158
mapAsync(res.value.links, (link, cb) => {
159-
self.dag._getRecursive(link.multihash, cb)
159+
self.dag._getRecursive(link.cid, cb)
160160
}, (err, nodes) => {
161161
// console.log('nodes:', nodes)
162162
if (err) return callback(err)

src/core/components/init.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ module.exports = function init (self) {
115115
(cb) => {
116116
waterfall([
117117
(cb) => self.object.new('unixfs-dir', cb),
118-
(emptyDirNode, cb) => self._ipns.initializeKeyspace(privateKey, emptyDirNode.toJSON().multihash, cb)
118+
(node, cb) => self._ipns.initializeKeyspace(privateKey, node.cid.toBaseEncodedString(), cb)
119119
], cb)
120120
}
121121
]

0 commit comments

Comments
 (0)