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

Commit 813048f

Browse files
achingbrainAlan Shaw
authored and
Alan Shaw
committed
refactor: update ipld formats, async/await mfs/unixfs & base32 cids (#2068)
This is part of the Awesome Endeavour: Async Iterators: #1670 Depends on * [x] ipld/js-ipld-dag-pb#137 * [x] ipfs-inactive/interface-js-ipfs-core#473 * [x] ipfs-inactive/js-ipfs-http-client#1010 * [x] ipfs/js-ipfs-http-response#25 resolves #1995 BREAKING CHANGE: The default string encoding for version 1 CIDs has changed to `base32`. IPLD formats have been updated to the latest versions. IPLD nodes returned by `ipfs.dag` and `ipfs.object` commands have significant breaking changes. If you are using these commands in your application you are likely to encounter the following changes to `dag-pb` nodes (the default node type that IPFS creates): * `DAGNode` properties have been renamed as follows: * `data` => `Data` * `links` => `Links` * `size` => `size` (Note: no change) * `DAGLink` properties have been renamed as follows: * `cid` => `Hash` * `name` => `Name` * `size` => `Tsize` See CHANGELOGs for each IPLD format for it's respective changes, you can read more about the [`dag-pb` changes in the CHANGELOG](https://github.com./ipld/js-ipld-dag-pb/blob/master) License: MIT Signed-off-by: Alan Shaw <[email protected]>
1 parent e358529 commit 813048f

Some content is hidden

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

61 files changed

+812
-503
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

+29-24
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@
7272
"execa": "^1.0.0",
7373
"form-data": "^2.3.3",
7474
"hat": "0.0.3",
75+
"interface-ipfs-core": "~0.103.0",
7576
"ipfsd-ctl": "~0.42.0",
7677
"libp2p-websocket-star": "~0.10.2",
7778
"ncp": "^2.0.0",
7879
"qs": "^6.5.2",
7980
"rimraf": "^2.6.2",
80-
"interface-ipfs-core": "~0.102.0",
8181
"sinon": "^7.3.1",
8282
"stream-to-promise": "^2.2.0"
8383
},
@@ -86,6 +86,9 @@
8686
"@hapi/hapi": "^18.3.1",
8787
"@hapi/joi": "^15.0.1",
8888
"async": "^2.6.1",
89+
"async-iterator-all": "0.0.2",
90+
"async-iterator-to-pull-stream": "^1.1.0",
91+
"async-iterator-to-stream": "^1.1.0",
8992
"base32.js": "~0.1.0",
9093
"bignumber.js": "^8.0.2",
9194
"binary-querystring": "~0.1.2",
@@ -94,8 +97,9 @@
9497
"bs58": "^4.0.1",
9598
"buffer-peek-stream": "^1.0.1",
9699
"byteman": "^1.3.5",
97-
"cid-tool": "~0.2.0",
98-
"cids": "~0.5.8",
100+
"callbackify": "^1.1.0",
101+
"cid-tool": "~0.3.0",
102+
"cids": "~0.7.1",
99103
"class-is": "^1.1.0",
100104
"datastore-core": "~0.6.0",
101105
"datastore-pubsub": "~0.1.1",
@@ -109,39 +113,39 @@
109113
"glob": "^7.1.3",
110114
"hapi-pino": "^6.0.0",
111115
"human-to-milliseconds": "^1.0.0",
112-
"interface-datastore": "~0.7.0",
113-
"ipfs-bitswap": "~0.23.0",
114-
"ipfs-block": "~0.8.0",
116+
"interface-datastore": "~0.6.0",
117+
"ipfs-bitswap": "~0.24.0",
118+
"ipfs-block": "~0.8.1",
115119
"ipfs-block-service": "~0.15.1",
116-
"ipfs-http-client": "^31.1.0",
117-
"ipfs-http-response": "~0.2.1",
118-
"ipfs-mfs": "~0.10.2",
120+
"ipfs-http-client": "^32.0.0",
121+
"ipfs-http-response": "~0.3.0",
122+
"ipfs-mfs": "~0.11.2",
119123
"ipfs-multipart": "~0.1.0",
120-
"ipfs-repo": "~0.26.5",
124+
"ipfs-repo": "~0.26.6",
121125
"ipfs-unixfs": "~0.1.16",
122-
"ipfs-unixfs-exporter": "~0.36.1",
123-
"ipfs-unixfs-importer": "~0.38.5",
124-
"ipld": "~0.21.1",
125-
"ipld-bitcoin": "~0.1.8",
126-
"ipld-dag-cbor": "~0.13.1",
127-
"ipld-dag-pb": "~0.15.3",
128-
"ipld-ethereum": "^2.0.1",
129-
"ipld-git": "~0.3.0",
130-
"ipld-raw": "^2.0.1",
131-
"ipld-zcash": "~0.1.6",
126+
"ipfs-unixfs-exporter": "~0.37.4",
127+
"ipfs-unixfs-importer": "~0.39.6",
128+
"ipfs-utils": "~0.0.3",
129+
"ipld": "~0.24.1",
130+
"ipld-bitcoin": "~0.3.0",
131+
"ipld-dag-cbor": "~0.15.0",
132+
"ipld-dag-pb": "~0.17.3",
133+
"ipld-ethereum": "^4.0.0",
134+
"ipld-git": "~0.5.0",
135+
"ipld-raw": "^4.0.0",
136+
"ipld-zcash": "~0.3.0",
132137
"ipns": "~0.5.0",
133-
"is-ipfs": "~0.6.0",
138+
"is-ipfs": "~0.6.1",
134139
"is-pull-stream": "~0.0.0",
135140
"is-stream": "^2.0.0",
136141
"iso-url": "~0.4.6",
137-
"ipfs-utils": "~0.0.3",
138142
"just-flatten-it": "^2.1.0",
139143
"just-safe-set": "^2.1.0",
140144
"kind-of": "^6.0.2",
141145
"libp2p": "~0.25.3",
142146
"libp2p-bootstrap": "~0.9.3",
143147
"libp2p-crypto": "~0.16.0",
144-
"libp2p-kad-dht": "~0.14.12",
148+
"libp2p-kad-dht": "~0.15.0",
145149
"libp2p-keychain": "~0.4.1",
146150
"libp2p-mdns": "~0.12.0",
147151
"libp2p-record": "~0.6.1",
@@ -158,7 +162,7 @@
158162
"multiaddr": "^6.0.5",
159163
"multiaddr-to-uri": "^4.0.1",
160164
"multibase": "~0.6.0",
161-
"multicodec": "~0.5.0",
165+
"multicodec": "~0.5.1",
162166
"multihashes": "~0.4.14",
163167
"multihashing-async": "~0.6.0",
164168
"node-fetch": "^2.3.0",
@@ -177,6 +181,7 @@
177181
"pull-pushable": "^2.2.0",
178182
"pull-sort": "^1.0.1",
179183
"pull-stream": "^3.6.9",
184+
"pull-stream-to-async-iterator": "^1.0.1",
180185
"pull-stream-to-stream": "^1.3.4",
181186
"pull-traverse": "^1.0.3",
182187
"readable-stream": "^3.1.1",

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')
@@ -35,7 +47,7 @@ async function main (args) {
3547
}
3648
})
3749
.catch(({ error, argv }) => {
38-
getIpfs = argv.getIpfs
50+
getIpfs = argv && argv.getIpfs
3951
debug(error)
4052
// the argument can have a different shape depending on where the error came from
4153
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) {

0 commit comments

Comments
 (0)