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

Commit e7b7047

Browse files
committed
chore: update ipld formats, async/await mfs and unixfs and base32 cids
1 parent a189a47 commit e7b7047

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+475
-306
lines changed

examples/traverse-ipld-graphs/get-path-accross-formats.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,20 @@ createNode((err, ipfs) => {
1717
series([
1818
(cb) => {
1919
const someData = Buffer.from('capoeira')
20+
let node
2021

21-
dagPB.DAGNode.create(someData, (err, node) => {
22+
try {
23+
node = dagPB.DAGNode.create(someData)
24+
} catch (err) {
25+
return cb(err)
26+
}
27+
28+
ipfs.dag.put(node, { format: 'dag-pb', hashAlg: 'sha2-256' }, (err, cid) => {
2229
if (err) {
2330
cb(err)
2431
}
25-
26-
ipfs.dag.put(node, { format: 'dag-pb', hashAlg: 'sha2-256' }, (err, cid) => {
27-
if (err) {
28-
cb(err)
29-
}
30-
cidPBNode = cid
31-
cb()
32-
})
32+
cidPBNode = cid
33+
cb()
3334
})
3435
},
3536
(cb) => {

examples/traverse-ipld-graphs/tree.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,20 @@ createNode((err, ipfs) => {
1717
series([
1818
(cb) => {
1919
const someData = Buffer.from('capoeira')
20+
let node
2021

21-
dagPB.DAGNode.create(someData, (err, node) => {
22+
try {
23+
dagPB.DAGNode.create(someData)
24+
} catch (err) {
25+
return cb(err)
26+
}
27+
28+
ipfs.dag.put(node, { format: 'dag-pb', hashAlg: 'sha2-256' }, (err, cid) => {
2229
if (err) {
2330
cb(err)
2431
}
25-
26-
ipfs.dag.put(node, { format: 'dag-pb', hashAlg: 'sha2-256' }, (err, cid) => {
27-
if (err) {
28-
cb(err)
29-
}
30-
cidPBNode = cid
31-
cb()
32-
})
32+
cidPBNode = cid
33+
cb()
3334
})
3435
},
3536
(cb) => {

package.json

+23-22
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"execa": "^1.0.0",
7373
"form-data": "^2.3.3",
7474
"hat": "0.0.3",
75-
"interface-ipfs-core": "~0.100.0",
75+
"interface-ipfs-core": "ipfs/interface-js-ipfs-core#update-cids-and-oh-wait",
7676
"ipfsd-ctl": "~0.42.0",
7777
"libp2p-websocket-star": "~0.10.2",
7878
"ncp": "^2.0.0",
@@ -96,8 +96,9 @@
9696
"bs58": "^4.0.1",
9797
"buffer-peek-stream": "^1.0.1",
9898
"byteman": "^1.3.5",
99-
"cid-tool": "~0.2.0",
100-
"cids": "~0.5.8",
99+
"callbackify": "^1.1.0",
100+
"cid-tool": "~0.3.0",
101+
"cids": "~0.7.1",
101102
"class-is": "^1.1.0",
102103
"datastore-core": "~0.6.0",
103104
"datastore-pubsub": "~0.1.1",
@@ -112,27 +113,27 @@
112113
"hapi-pino": "^5.4.1",
113114
"human-to-milliseconds": "^1.0.0",
114115
"interface-datastore": "~0.6.0",
115-
"ipfs-bitswap": "~0.23.0",
116-
"ipfs-block": "~0.8.0",
116+
"ipfs-bitswap": "~0.24.0",
117+
"ipfs-block": "~0.8.1",
117118
"ipfs-block-service": "~0.15.1",
118-
"ipfs-http-client": "^30.1.1",
119-
"ipfs-http-response": "~0.2.1",
120-
"ipfs-mfs": "~0.10.2",
119+
"ipfs-http-client": "ipfs/js-ipfs-http-client#update-ipld-formats",
120+
"ipfs-http-response": "ipfs/js-ipfs-http-response#update-ipld-formats",
121+
"ipfs-mfs": "~0.11.0",
121122
"ipfs-multipart": "~0.1.0",
122-
"ipfs-repo": "~0.26.1",
123+
"ipfs-repo": "~0.26.6",
123124
"ipfs-unixfs": "~0.1.16",
124-
"ipfs-unixfs-exporter": "~0.36.1",
125-
"ipfs-unixfs-importer": "~0.38.5",
126-
"ipld": "~0.22.0",
127-
"ipld-bitcoin": "~0.1.8",
128-
"ipld-dag-cbor": "~0.13.1",
129-
"ipld-dag-pb": "~0.15.3",
130-
"ipld-ethereum": "^2.0.1",
131-
"ipld-git": "~0.3.0",
132-
"ipld-raw": "^2.0.1",
133-
"ipld-zcash": "~0.1.6",
125+
"ipfs-unixfs-exporter": "~0.37.0",
126+
"ipfs-unixfs-importer": "~0.39.2",
127+
"ipld": "~0.24.1",
128+
"ipld-bitcoin": "~0.3.0",
129+
"ipld-dag-cbor": "~0.15.0",
130+
"ipld-dag-pb": "~0.17.0",
131+
"ipld-ethereum": "^4.0.0",
132+
"ipld-git": "~0.5.0",
133+
"ipld-raw": "^4.0.0",
134+
"ipld-zcash": "~0.3.0",
134135
"ipns": "~0.5.0",
135-
"is-ipfs": "~0.6.0",
136+
"is-ipfs": "~0.6.1",
136137
"is-pull-stream": "~0.0.0",
137138
"is-stream": "^2.0.0",
138139
"iso-url": "~0.4.6",
@@ -141,7 +142,7 @@
141142
"libp2p": "~0.25.0",
142143
"libp2p-bootstrap": "~0.9.3",
143144
"libp2p-crypto": "~0.16.0",
144-
"libp2p-kad-dht": "~0.14.12",
145+
"libp2p-kad-dht": "~0.15.0",
145146
"libp2p-keychain": "~0.4.1",
146147
"libp2p-mdns": "~0.12.0",
147148
"libp2p-record": "~0.6.1",
@@ -158,7 +159,7 @@
158159
"multiaddr": "^6.0.5",
159160
"multiaddr-to-uri": "^4.0.1",
160161
"multibase": "~0.6.0",
161-
"multicodec": "~0.5.0",
162+
"multicodec": "~0.5.1",
162163
"multihashes": "~0.4.14",
163164
"multihashing-async": "~0.6.0",
164165
"node-fetch": "^2.3.0",

src/cli/bin.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

33
'use strict'
44

5+
process.on('uncaughtException', (err) => {
6+
console.info(err)
7+
8+
throw err
9+
})
10+
11+
process.on('unhandledRejection', (err) => {
12+
console.info(err)
13+
14+
throw err
15+
})
16+
517
const YargsPromise = require('yargs-promise')
618
const updateNotifier = require('update-notifier')
719
const utils = require('./utils')
@@ -31,7 +43,7 @@ async function main (args) {
3143
}
3244
})
3345
.catch(({ error, argv }) => {
34-
getIpfs = argv.getIpfs
46+
getIpfs = argv && argv.getIpfs
3547
debug(error)
3648
// the argument can have a different shape depending on where the error came from
3749
if (error.message || (error.error && error.error.message)) {

src/cli/commands/dag/get.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module.exports = {
3232
try {
3333
result = await ipfs.dag.get(cid, path, options)
3434
} catch (err) {
35-
return print(`dag get failed: ${err.message}`)
35+
return print(`dag get failed: ${err}`)
3636
}
3737

3838
if (options.localResolve) {

src/cli/commands/object/get.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@ module.exports = {
2525
resolve((async () => {
2626
const ipfs = await getIpfs()
2727
const node = await ipfs.object.get(key, { enc: 'base58' })
28-
let data = node.data
28+
let data = node.Data || ''
2929

3030
if (Buffer.isBuffer(data)) {
31-
data = node.data.toString(dataEncoding || undefined)
31+
data = node.Data.toString(dataEncoding || undefined)
3232
}
3333

3434
const answer = {
3535
Data: data,
3636
Hash: cidToString(key, { base: cidBase, upgrade: false }),
37-
Size: node.size,
38-
Links: node.links.map((l) => {
37+
Size: node.Size,
38+
Links: node.Links.map((l) => {
3939
return {
40-
Name: l.name,
41-
Size: l.size,
42-
Hash: cidToString(l.cid, { base: cidBase, upgrade: false })
40+
Name: l.Name,
41+
Size: l.Tsize,
42+
Hash: cidToString(l.Hash, { base: cidBase, upgrade: false })
4343
}
4444
})
4545
}

src/cli/commands/object/links.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ module.exports = {
2323
const links = await ipfs.object.links(key, { enc: 'base58' })
2424

2525
links.forEach((link) => {
26-
const cidStr = cidToString(link.cid, { base: cidBase, upgrade: false })
27-
print(`${cidStr} ${link.size} ${link.name}`)
26+
const cidStr = cidToString(link.Hash, { base: cidBase, upgrade: false })
27+
print(`${cidStr} ${link.Tsize} ${link.Name}`)
2828
})
2929
})())
3030
}

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

+9-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
const dagPB = require('ipld-dag-pb')
44
const DAGLink = dagPB.DAGLink
55
const multibase = require('multibase')
6-
const promisify = require('promisify-es6')
76
const { print } = require('../../../utils')
87
const { cidToString } = require('../../../../utils/cid')
98

@@ -17,14 +16,21 @@ module.exports = {
1716
describe: 'Number base to display CIDs in. Note: specifying a CID base for v0 CIDs will have no effect.',
1817
type: 'string',
1918
choices: multibase.names
19+
},
20+
'cid-version': {
21+
describe: 'The CID version of the DAGNode to link to',
22+
type: 'number',
23+
default: 0
2024
}
2125
},
2226

23-
handler ({ getIpfs, root, name, ref, cidBase, resolve }) {
27+
handler ({ getIpfs, root, name, ref, cidBase, cidVersion, resolve }) {
2428
resolve((async () => {
2529
const ipfs = await getIpfs()
2630
const nodeA = await ipfs.object.get(ref, { enc: 'base58' })
27-
const result = await promisify(dagPB.util.cid)(nodeA)
31+
const result = await dagPB.util.cid(dagPB.util.serialize(nodeA), {
32+
cidVersion
33+
})
2834
const link = new DAGLink(name, nodeA.size, result)
2935
const cid = await ipfs.object.patch.addLink(root, link, { enc: 'base58' })
3036
print(cidToString(cid, { base: cidBase, upgrade: false }))

src/core/components/bitswap.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const PeerId = require('peer-id')
99
const errCode = require('err-code')
1010

1111
function formatWantlist (list, cidBase) {
12-
return Array.from(list).map((e) => ({ '/': e[1].cid.toBaseEncodedString() }))
12+
return Array.from(list).map((e) => ({ '/': e[1].cid.toBaseEncodedString(cidBase) }))
1313
}
1414

1515
module.exports = function bitswap (self) {

src/core/components/dag.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ module.exports = function dag (self) {
4545

4646
// js-ipld defaults to verion 1 CIDs. Hence set version 0 explicitly for
4747
// dag-pb nodes
48-
if (options.format === multicodec.DAG_PB &&
49-
options.hashAlg === multicodec.SHA2_256 &&
50-
options.version === undefined) {
51-
options.version = 0
48+
if (options.version === undefined) {
49+
if (options.format === multicodec.DAG_PB && options.hashAlg === multicodec.SHA2_256) {
50+
options.version = 0
51+
} else {
52+
options.version = 1
53+
}
5254
}
5355

5456
self._ipld.put(dagNode, options.format, {
@@ -125,9 +127,7 @@ module.exports = function dag (self) {
125127
)
126128
} else {
127129
const result = self._ipld.resolve(cid, path)
128-
const promisedValue = options.localResolve ?
129-
result.first() :
130-
result.last()
130+
const promisedValue = options.localResolve ? result.first() : result.last()
131131
promisedValue.then(
132132
(value) => callback(null, value),
133133
(error) => callback(error)
@@ -204,8 +204,8 @@ module.exports = function dag (self) {
204204
self.dag.get(cid, '', options, (err, res) => {
205205
if (err) { return callback(err) }
206206

207-
mapAsync(res.value.links, (link, cb) => {
208-
self.dag._getRecursive(link.cid, options, cb)
207+
mapAsync(res.value.Links, (link, cb) => {
208+
self.dag._getRecursive(link.Hash, options, cb)
209209
}, (err, nodes) => {
210210
// console.log('nodes:', nodes)
211211
if (err) return callback(err)

0 commit comments

Comments
 (0)