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

Commit

Permalink
chore: update ipld formats, async/await mfs and unixfs and base32 cids
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain authored and alanshaw committed May 20, 2019
1 parent 607623d commit 6c7f4ec
Show file tree
Hide file tree
Showing 49 changed files with 476 additions and 307 deletions.
19 changes: 10 additions & 9 deletions examples/traverse-ipld-graphs/get-path-accross-formats.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,20 @@ createNode((err, ipfs) => {
series([
(cb) => {
const someData = Buffer.from('capoeira')
let node

dagPB.DAGNode.create(someData, (err, node) => {
try {
node = dagPB.DAGNode.create(someData)
} catch (err) {
return cb(err)
}

ipfs.dag.put(node, { format: 'dag-pb', hashAlg: 'sha2-256' }, (err, cid) => {
if (err) {
cb(err)
}

ipfs.dag.put(node, { format: 'dag-pb', hashAlg: 'sha2-256' }, (err, cid) => {
if (err) {
cb(err)
}
cidPBNode = cid
cb()
})
cidPBNode = cid
cb()
})
},
(cb) => {
Expand Down
19 changes: 10 additions & 9 deletions examples/traverse-ipld-graphs/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,20 @@ createNode((err, ipfs) => {
series([
(cb) => {
const someData = Buffer.from('capoeira')
let node

dagPB.DAGNode.create(someData, (err, node) => {
try {
dagPB.DAGNode.create(someData)
} catch (err) {
return cb(err)
}

ipfs.dag.put(node, { format: 'dag-pb', hashAlg: 'sha2-256' }, (err, cid) => {
if (err) {
cb(err)
}

ipfs.dag.put(node, { format: 'dag-pb', hashAlg: 'sha2-256' }, (err, cid) => {
if (err) {
cb(err)
}
cidPBNode = cid
cb()
})
cidPBNode = cid
cb()
})
},
(cb) => {
Expand Down
47 changes: 24 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"execa": "^1.0.0",
"form-data": "^2.3.3",
"hat": "0.0.3",
"interface-ipfs-core": "~0.102.0",
"interface-ipfs-core": "ipfs/interface-js-ipfs-core#update-cids-and-oh-wait",
"ipfsd-ctl": "~0.42.0",
"libp2p-websocket-star": "~0.10.2",
"ncp": "^2.0.0",
Expand All @@ -97,8 +97,9 @@
"bs58": "^4.0.1",
"buffer-peek-stream": "^1.0.1",
"byteman": "^1.3.5",
"cid-tool": "~0.2.0",
"cids": "~0.5.8",
"callbackify": "^1.1.0",
"cid-tool": "~0.3.0",
"cids": "~0.7.1",
"class-is": "^1.1.0",
"datastore-core": "~0.6.0",
"datastore-pubsub": "~0.1.1",
Expand All @@ -112,28 +113,28 @@
"glob": "^7.1.3",
"hapi-pino": "^6.0.0",
"human-to-milliseconds": "^1.0.0",
"interface-datastore": "~0.7.0",
"ipfs-bitswap": "~0.23.0",
"ipfs-block": "~0.8.0",
"interface-datastore": "~0.6.0",
"ipfs-bitswap": "~0.24.0",
"ipfs-block": "~0.8.1",
"ipfs-block-service": "~0.15.1",
"ipfs-http-client": "^31.1.0",
"ipfs-http-response": "~0.2.1",
"ipfs-mfs": "~0.10.2",
"ipfs-http-client": "ipfs/js-ipfs-http-client#update-ipld-formats",
"ipfs-http-response": "ipfs/js-ipfs-http-response#update-ipld-formats",
"ipfs-mfs": "~0.11.0",
"ipfs-multipart": "~0.1.0",
"ipfs-repo": "~0.26.5",
"ipfs-repo": "~0.26.6",
"ipfs-unixfs": "~0.1.16",
"ipfs-unixfs-exporter": "~0.36.1",
"ipfs-unixfs-importer": "~0.38.5",
"ipld": "~0.22.0",
"ipld-bitcoin": "~0.1.8",
"ipld-dag-cbor": "~0.13.1",
"ipld-dag-pb": "~0.15.3",
"ipld-ethereum": "^2.0.1",
"ipld-git": "~0.3.0",
"ipld-raw": "^2.0.1",
"ipld-zcash": "~0.1.6",
"ipfs-unixfs-exporter": "~0.37.0",
"ipfs-unixfs-importer": "~0.39.4",
"ipld": "~0.24.1",
"ipld-bitcoin": "~0.3.0",
"ipld-dag-cbor": "~0.15.0",
"ipld-dag-pb": "~0.17.0",
"ipld-ethereum": "^4.0.0",
"ipld-git": "~0.5.0",
"ipld-raw": "^4.0.0",
"ipld-zcash": "~0.3.0",
"ipns": "~0.5.0",
"is-ipfs": "~0.6.0",
"is-ipfs": "~0.6.1",
"is-pull-stream": "~0.0.0",
"is-stream": "^2.0.0",
"iso-url": "~0.4.6",
Expand All @@ -144,7 +145,7 @@
"libp2p": "~0.25.0",
"libp2p-bootstrap": "~0.9.3",
"libp2p-crypto": "~0.16.0",
"libp2p-kad-dht": "~0.14.12",
"libp2p-kad-dht": "~0.15.0",
"libp2p-keychain": "~0.4.1",
"libp2p-mdns": "~0.12.0",
"libp2p-record": "~0.6.1",
Expand All @@ -161,7 +162,7 @@
"multiaddr": "^6.0.5",
"multiaddr-to-uri": "^4.0.1",
"multibase": "~0.6.0",
"multicodec": "~0.5.0",
"multicodec": "~0.5.1",
"multihashes": "~0.4.14",
"multihashing-async": "~0.6.0",
"node-fetch": "^2.3.0",
Expand Down
14 changes: 13 additions & 1 deletion src/cli/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

'use strict'

process.on('uncaughtException', (err) => {
console.info(err)

throw err
})

process.on('unhandledRejection', (err) => {
console.info(err)

throw err
})

const YargsPromise = require('yargs-promise')
const updateNotifier = require('update-notifier')
const utils = require('./utils')
Expand Down Expand Up @@ -35,7 +47,7 @@ async function main (args) {
}
})
.catch(({ error, argv }) => {
getIpfs = argv.getIpfs
getIpfs = argv && argv.getIpfs
debug(error)
// the argument can have a different shape depending on where the error came from
if (error.message || (error.error && error.error.message)) {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/dag/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = {
try {
result = await ipfs.dag.get(cid, path, options)
} catch (err) {
return print(`dag get failed: ${err.message}`)
return print(`dag get failed: ${err}`)
}

if (options.localResolve) {
Expand Down
14 changes: 7 additions & 7 deletions src/cli/commands/object/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ module.exports = {
resolve((async () => {
const ipfs = await getIpfs()
const node = await ipfs.object.get(key, { enc: 'base58' })
let data = node.data
let data = node.Data || ''

if (Buffer.isBuffer(data)) {
data = node.data.toString(dataEncoding || undefined)
data = node.Data.toString(dataEncoding || undefined)
}

const answer = {
Data: data,
Hash: cidToString(key, { base: cidBase, upgrade: false }),
Size: node.size,
Links: node.links.map((l) => {
Size: node.Size,
Links: node.Links.map((l) => {
return {
Name: l.name,
Size: l.size,
Hash: cidToString(l.cid, { base: cidBase, upgrade: false })
Name: l.Name,
Size: l.Tsize,
Hash: cidToString(l.Hash, { base: cidBase, upgrade: false })
}
})
}
Expand Down
4 changes: 2 additions & 2 deletions src/cli/commands/object/links.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ module.exports = {
const links = await ipfs.object.links(key, { enc: 'base58' })

links.forEach((link) => {
const cidStr = cidToString(link.cid, { base: cidBase, upgrade: false })
print(`${cidStr} ${link.size} ${link.name}`)
const cidStr = cidToString(link.Hash, { base: cidBase, upgrade: false })
print(`${cidStr} ${link.Tsize} ${link.Name}`)
})
})())
}
Expand Down
12 changes: 9 additions & 3 deletions src/cli/commands/object/patch/add-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const dagPB = require('ipld-dag-pb')
const DAGLink = dagPB.DAGLink
const multibase = require('multibase')
const promisify = require('promisify-es6')
const { print } = require('../../../utils')
const { cidToString } = require('../../../../utils/cid')

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

handler ({ getIpfs, root, name, ref, cidBase, resolve }) {
handler ({ getIpfs, root, name, ref, cidBase, cidVersion, resolve }) {
resolve((async () => {
const ipfs = await getIpfs()
const nodeA = await ipfs.object.get(ref, { enc: 'base58' })
const result = await promisify(dagPB.util.cid)(nodeA)
const result = await dagPB.util.cid(dagPB.util.serialize(nodeA), {
cidVersion
})
const link = new DAGLink(name, nodeA.size, result)
const cid = await ipfs.object.patch.addLink(root, link, { enc: 'base58' })
print(cidToString(cid, { base: cidBase, upgrade: false }))
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/bitswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const PeerId = require('peer-id')
const errCode = require('err-code')

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

module.exports = function bitswap (self) {
Expand Down
18 changes: 9 additions & 9 deletions src/core/components/dag.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ module.exports = function dag (self) {

// js-ipld defaults to verion 1 CIDs. Hence set version 0 explicitly for
// dag-pb nodes
if (options.format === multicodec.DAG_PB &&
options.hashAlg === multicodec.SHA2_256 &&
options.version === undefined) {
options.version = 0
if (options.version === undefined) {
if (options.format === multicodec.DAG_PB && options.hashAlg === multicodec.SHA2_256) {
options.version = 0
} else {
options.version = 1
}
}

self._ipld.put(dagNode, options.format, {
Expand Down Expand Up @@ -125,9 +127,7 @@ module.exports = function dag (self) {
)
} else {
const result = self._ipld.resolve(cid, path)
const promisedValue = options.localResolve ?
result.first() :
result.last()
const promisedValue = options.localResolve ? result.first() : result.last()
promisedValue.then(
(value) => callback(null, value),
(error) => callback(error)
Expand Down Expand Up @@ -204,8 +204,8 @@ module.exports = function dag (self) {
self.dag.get(cid, '', options, (err, res) => {
if (err) { return callback(err) }

mapAsync(res.value.links, (link, cb) => {
self.dag._getRecursive(link.cid, options, cb)
mapAsync(res.value.Links, (link, cb) => {
self.dag._getRecursive(link.Hash, options, cb)
}, (err, nodes) => {
// console.log('nodes:', nodes)
if (err) return callback(err)
Expand Down
Loading

0 comments on commit 6c7f4ec

Please sign in to comment.