Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
fix: updates ipld-dag-pb dep to version without .cid properties (#889)
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 authored and Alan Shaw committed Nov 13, 2018
1 parent 348a144 commit ac30a82
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion examples/bundle-browserify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"license": "MIT",
"devDependencies": {
"browserify": "^13.1.1",
"ipfs-api": "^24.0.0",
"ipfs-api": "../../",
"http-server": "~0.9.0"
},
"dependencies": {}
Expand Down
2 changes: 1 addition & 1 deletion examples/bundle-webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"devDependencies": {
"babel-core": "^5.4.7",
"babel-loader": "^5.1.2",
"ipfs-api": "^11.1.0",
"ipfs-api": "../../",
"json-loader": "~0.5.3",
"react": "~0.13.0",
"react-hot-loader": "^1.3.0",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"ipfs-block": "~0.8.0",
"ipfs-unixfs": "~0.1.16",
"ipld-dag-cbor": "~0.13.0",
"ipld-dag-pb": "~0.14.11",
"ipld-dag-pb": "~0.15.0",
"is-ipfs": "~0.4.7",
"is-pull-stream": "0.0.0",
"is-stream": "^1.1.0",
Expand Down Expand Up @@ -85,7 +85,7 @@
"eslint-plugin-react": "^7.11.1",
"go-ipfs-dep": "~0.4.18",
"gulp": "^3.9.1",
"interface-ipfs-core": "~0.84.3",
"interface-ipfs-core": "~0.85.0",
"ipfsd-ctl": "~0.40.0",
"pull-stream": "^3.6.9",
"stream-equal": "^1.1.1"
Expand Down
2 changes: 1 addition & 1 deletion src/object/addLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = (send) => {
args: [
multihash,
dLink.name,
cleanMultihash(dLink.multihash)
cleanMultihash(dLink.cid.buffer)
]
}, (err, result) => {
if (err) {
Expand Down
4 changes: 0 additions & 4 deletions src/object/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ module.exports = (send) => {
return callback(err)
}

if (node.toJSON().multihash !== result.Hash) {
return callback(new Error('multihashes do not match'))
}

callback(null, node)
})
})
Expand Down
20 changes: 10 additions & 10 deletions src/object/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ module.exports = (send) => {
Links: []
}
}
} else if (obj.multihash) {
} else if (DAGNode.isDAGNode(obj)) {
tmpObj = {
Data: obj.data.toString(),
Links: obj.links.map((l) => {
const link = l.toJSON()
link.hash = link.multihash
link.hash = link.cid
return link
})
}
Expand Down Expand Up @@ -82,7 +82,7 @@ module.exports = (send) => {

let node

if (obj.multihash) {
if (DAGNode.isDAGNode(obj)) {
node = obj
} else if (options.enc === 'protobuf') {
dagPB.util.deserialize(obj, (err, _node) => {
Expand All @@ -106,14 +106,14 @@ module.exports = (send) => {
next()

function next () {
const nodeJSON = node.toJSON()
if (nodeJSON.multihash !== result.Hash) {
const err = new Error('multihashes do not match')
return callback(err)
}
dagPB.util.cid(node, (err, cid) => {
if (err) {
return callback(err)
}

cache.set(result.Hash, node)
callback(null, node)
cache.set(cid.toBaseEncodedString(), node)
callback(null, node)
})
}
})
})
Expand Down
4 changes: 4 additions & 0 deletions src/utils/clean-multihash.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
'use strict'

const bs58 = require('bs58')
const CID = require('cids')
const isIPFS = require('is-ipfs')

module.exports = function (multihash) {
if (Buffer.isBuffer(multihash)) {
multihash = bs58.encode(multihash)
}
if (CID.isCID(multihash)) {
multihash = multihash.toBaseEncodedString()
}
if (typeof multihash !== 'string') {
throw new Error('unexpected multihash type: ' + typeof multihash)
}
Expand Down

0 comments on commit ac30a82

Please sign in to comment.