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

Commit

Permalink
fix: updates ipld-dag-pb dep to version without .cid properties
Browse files Browse the repository at this point in the history
Follows on from ipld/js-ipld-dag-pb#99 and
updates this module to not rely on DAGNodes having knowledge of
their CIDs.
  • Loading branch information
achingbrain committed Nov 8, 2018
1 parent 74edafd commit 2b5edc5
Show file tree
Hide file tree
Showing 18 changed files with 360 additions and 243 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"execa": "^1.0.0",
"form-data": "^2.3.3",
"hat": "0.0.3",
"interface-ipfs-core": "~0.83.0",
"interface-ipfs-core": "ipfs/interface-ipfs-core#update-dag-pb-to-not-have-cid-property",
"ipfsd-ctl": "~0.39.5",
"ncp": "^2.0.0",
"qs": "^6.5.2",
Expand Down Expand Up @@ -98,7 +98,7 @@
"hoek": "^5.0.4",
"human-to-milliseconds": "^1.0.0",
"interface-datastore": "~0.6.0",
"ipfs-api": "^26.0.3",
"ipfs-api": "ipfs/js-ipfs-api#update-dag-pb-to-not-have-cid-property",
"ipfs-bitswap": "~0.21.0",
"ipfs-block": "~0.8.0",
"ipfs-block-service": "~0.15.1",
Expand All @@ -108,10 +108,10 @@
"ipfs-repo": "~0.25.0",
"ipfs-unixfs": "~0.1.16",
"ipfs-unixfs-engine": "~0.33.0",
"ipld-dag-pb": "~0.14.11",
"ipns": "~0.3.0",
"ipld": "~0.19.1",
"ipld": "ipld/js-ipld#depend-on-dag-pb-without-cid",
"ipld-bitcoin": "~0.1.8",
"ipld-dag-pb": "ipld/js-ipld-dag-pb#remove-cid-property-from-dagnodes",
"ipld-ethereum": "^2.0.1",
"ipld-git": "~0.2.2",
"ipld-raw": "^2.0.1",
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/object/links.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = {
links.forEach((link) => {
link = link.toJSON()

print(`${link.multihash} ${link.size} ${link.name}`)
print(`${link.cid} ${link.size} ${link.name}`)
})
})
}
Expand Down
13 changes: 11 additions & 2 deletions src/cli/commands/object/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ const debug = require('debug')
const log = debug('cli:object')
log.error = debug('cli:object:error')
const print = require('../../utils').print
const {
util: {
cid
}
} = require('ipld-dag-pb')

module.exports = {
command: 'new [<template>]',
Expand All @@ -18,9 +23,13 @@ module.exports = {
throw err
}

const nodeJSON = node.toJSON()
cid(node, (err, cid) => {
if (err) {
throw err
}

print(nodeJSON.multihash)
print(cid.toBaseEncodedString())
})
})
}
}
29 changes: 23 additions & 6 deletions src/cli/commands/object/patch/add-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
const dagPB = require('ipld-dag-pb')
const DAGLink = dagPB.DAGLink
const print = require('../../../utils').print
const {
util: {
cid
}
} = require('ipld-dag-pb')

module.exports = {
command: 'add-link <root> <name> <ref>',
Expand All @@ -20,16 +25,28 @@ module.exports = {
throw err
}

const link = new DAGLink(argv.name, nodeA.size, nodeA.multihash)

ipfs.object.patch.addLink(argv.root, link, {
enc: 'base58'
}, (err, nodeB) => {
cid(nodeA, (err, result) => {
if (err) {
throw err
}

print(nodeB.toJSON().multihash)
const link = new DAGLink(argv.name, nodeA.size, result)

ipfs.object.patch.addLink(argv.root, link, {
enc: 'base58'
}, (err, nodeB) => {
if (err) {
throw err
}

cid(nodeB, (err, result) => {
if (err) {
throw err
}

print(result.toBaseEncodedString())
})
})
})
})
}
Expand Down
14 changes: 12 additions & 2 deletions src/cli/commands/object/patch/append-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ const debug = require('debug')
const log = debug('cli:object')
log.error = debug('cli:object:error')
const print = require('../../../utils').print
const {
util: {
cid
}
} = require('ipld-dag-pb')

function appendData (key, data, ipfs) {
ipfs.object.patch.appendData(key, data, {
Expand All @@ -14,9 +19,14 @@ function appendData (key, data, ipfs) {
if (err) {
throw err
}
const nodeJSON = node.toJSON()

print(nodeJSON.multihash)
cid(node, (err, cid) => {
if (err) {
throw err
}

print(cid.toBaseEncodedString())
})
})
}

Expand Down
13 changes: 11 additions & 2 deletions src/cli/commands/object/patch/rm-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ const debug = require('debug')
const log = debug('cli:object')
log.error = debug('cli:object:error')
const print = require('../../../utils').print
const {
util: {
cid
}
} = require('ipld-dag-pb')

module.exports = {
command: 'rm-link <root> <link>',
Expand All @@ -20,9 +25,13 @@ module.exports = {
throw err
}

const nodeJSON = node.toJSON()
cid(node, (err, cid) => {
if (err) {
throw err
}

print(nodeJSON.multihash)
print(cid.toBaseEncodedString())
})
})
}
}
14 changes: 12 additions & 2 deletions src/cli/commands/object/patch/set-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ const debug = require('debug')
const log = debug('cli:object')
log.error = debug('cli:object:error')
const print = require('../../../utils').print
const {
util: {
cid
}
} = require('ipld-dag-pb')

function parseAndAddNode (key, data, ipfs) {
ipfs.object.patch.setData(key, data, {
Expand All @@ -14,9 +19,14 @@ function parseAndAddNode (key, data, ipfs) {
if (err) {
throw err
}
const nodeJSON = node.toJSON()

print(nodeJSON.multihash)
cid(node, (err, cid) => {
if (err) {
throw err
}

print(cid.toBaseEncodedString())
})
})
}

Expand Down
13 changes: 11 additions & 2 deletions src/cli/commands/object/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,25 @@
const bl = require('bl')
const fs = require('fs')
const print = require('../../utils').print
const {
util: {
cid
}
} = require('ipld-dag-pb')

function putNode (buf, enc, ipfs) {
ipfs.object.put(buf, {enc: enc}, (err, node) => {
if (err) {
throw err
}

const nodeJSON = node.toJSON()
cid(node, (err, cid) => {
if (err) {
throw err
}

print(`added ${nodeJSON.multihash}`)
print(`added ${cid.toBaseEncodedString()}`)
})
})
}

Expand Down
15 changes: 0 additions & 15 deletions src/cli/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,6 @@ const Progress = require('progress')
const byteman = require('byteman')
const promisify = require('promisify-es6')

// All known IPLD formats
const ipldBitcoin = require('ipld-bitcoin')
const ipldDagCbor = require('ipld-dag-cbor')
const ipldDagPb = require('ipld-dag-pb')
const ipldEthAccountSnapshot = require('ipld-ethereum').ethAccountSnapshot
const ipldEthBlock = require('ipld-ethereum').ethBlock
const ipldEthBlockList = require('ipld-ethereum').ethBlockList
const ipldEthStateTrie = require('ipld-ethereum').ethStateTrie
const ipldEthStorageTrie = require('ipld-ethereum').ethStorageTrie
const ipldEthTrie = require('ipld-ethereum').ethTxTrie
const ipldEthTx = require('ipld-ethereum').ethTx
const ipldGit = require('ipld-git')
const ipldRaw = require('ipld-raw')
const ipldZcash = require('ipld-zcash')

exports = module.exports

exports.isDaemonOn = isDaemonOn
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/dag.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ module.exports = function dag (self) {
if (err) { return callback(err) }

mapAsync(res.value.links, (link, cb) => {
self.dag._getRecursive(link.multihash, cb)
self.dag._getRecursive(link.cid, cb)
}, (err, nodes) => {
// console.log('nodes:', nodes)
if (err) return callback(err)
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ module.exports = function init (self) {
(cb) => {
waterfall([
(cb) => self.object.new('unixfs-dir', cb),
(emptyDirNode, cb) => self._ipns.initializeKeyspace(privateKey, emptyDirNode.toJSON().multihash, cb)
(node, cb) => self._ipns.initializeKeyspace(privateKey, node.cid.toBaseEncodedString(), cb)
], cb)
}
]
Expand Down
Loading

0 comments on commit 2b5edc5

Please sign in to comment.