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

Commit

Permalink
chore: update to js-ipld 0.19
Browse files Browse the repository at this point in the history
BREAKING CHANGE: dag-cbor nodes now represent links as CID objects

The API for [dag-cbor](https://github.com/ipld/js-ipld-dag-cbor) changed.
Links are no longer represented as JSON objects (`{"/": "base-encoded-cid"}`,
but as [CID objects](https://github.com/ipld/js-cid). `ipfs.dag.get()` and now always return links as CID objects. `ipfs.dag.put()` also expects links to be represented as CID objects. The old-style JSON objects representation is still
supported, but deprecated.

Prior to this change:

```js
const cid = new CID('QmXed8RihWcWFXRRmfSRG9yFjEbXNxu1bDwgCFAN8Dxcq5')
// Link as JSON object representation
const putCid = await ipfs.dag.put({link: {'/': cid.toBaseEncodedString()}})
const result = await ipfs.dag.get(putCid)
console.log(result.value)

```

Output:

```js
{ link:
   { '/':
      <Buffer 12 20 8a…> } }
```

Now:

```js
const cid = new CID('QmXed8RihWcWFXRRmfSRG9yFjEbXNxu1bDwgCFAN8Dxcq5')
// Link as CID object
const putCid = await ipfs.dag.put({link: cid})
const result = await ipfs.dag.get(putCid)
console.log(result.value)
```

Output:

```js
{ link:
   CID {
     codec: 'dag-pb',
     version: 0,
     multihash:
      <Buffer 12 20 8a…> } }
```

See ipld/ipld#44 for more information on why this
change was made.
  • Loading branch information
vmx committed Oct 25, 2018
1 parent 9a82b05 commit e0005e8
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 9 deletions.
2 changes: 1 addition & 1 deletion examples/traverse-ipld-graphs/get-path-accross-formats.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ createNode((err, ipfs) => {
const myData = {
name: 'David',
likes: ['js-ipfs', 'icecream', 'steak'],
hobbies: [{ '/': cidPBNode.toBaseEncodedString() }]
hobbies: [cidPBNode]
}

ipfs.dag.put(myData, { format: 'dag-cbor', hashAlg: 'sha3-512' }, (err, cid) => {
Expand Down
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"expose-loader": "~0.7.5",
"form-data": "^2.3.2",
"hat": "0.0.3",
"interface-ipfs-core": "~0.78.0",
"interface-ipfs-core": "~0.79.0",
"ipfsd-ctl": "~0.39.3",
"mocha": "^5.2.0",
"ncp": "^2.0.0",
Expand Down Expand Up @@ -117,9 +117,14 @@
"ipfs-repo": "~0.24.0",
"ipfs-unixfs": "~0.1.15",
"ipfs-unixfs-engine": "~0.32.3",
"ipld": "~0.17.3",
"ipld-dag-cbor": "~0.12.1",
"ipld": "~0.19.0",
"ipld-bitcoin": "~0.1.8",
"ipld-dag-cbor": "~0.13.0",
"ipld-dag-pb": "~0.14.6",
"ipld-ethereum": "^2.0.1",
"ipld-git": "~0.2.2",
"ipld-raw": "^2.0.1",
"ipld-zcash": "~0.1.6",
"ipns": "~0.2.0",
"is-ipfs": "~0.4.2",
"is-pull-stream": "~0.0.0",
Expand Down
15 changes: 15 additions & 0 deletions src/cli/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ 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
30 changes: 25 additions & 5 deletions src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ const BlockService = require('ipfs-block-service')
const Ipld = require('ipld')
const PeerId = require('peer-id')
const PeerInfo = require('peer-info')
const dagCBOR = require('ipld-dag-cbor')
const dagPB = require('ipld-dag-pb')
const crypto = require('libp2p-crypto')
const isIPFS = require('is-ipfs')
const multiaddr = require('multiaddr')
Expand All @@ -17,6 +15,21 @@ const debug = require('debug')
const extend = require('deep-extend')
const EventEmitter = require('events')

// 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')

const config = require('./config')
const boot = require('./boot')
const components = require('./components')
Expand Down Expand Up @@ -75,8 +88,8 @@ class IPFS extends EventEmitter {
multibase: multibase,
multihash: multihash,
CID: CID,
dagPB: dagPB,
dagCBOR: dagCBOR
dagPB: ipldDagPb,
dagCBOR: ipldDagCbor
}

// IPFS Core Internals
Expand All @@ -86,7 +99,14 @@ class IPFS extends EventEmitter {
this._libp2pNode = undefined
this._bitswap = undefined
this._blockService = new BlockService(this._repo)
this._ipld = new Ipld(this._blockService)
this._ipld = new Ipld({
blockService: this._blockService,
formats: [
ipldBitcoin, ipldDagCbor, ipldDagPb, ipldEthAccountSnapshot,
ipldEthBlock, ipldEthBlockList, ipldEthStateTrie, ipldEthStorageTrie,
ipldEthTrie, ipldEthTx, ipldGit, ipldRaw, ipldZcash
]
})
this._preload = preload(this)
this._mfsPreload = mfsPreload(this)
this._ipns = new IPNS(null, this)
Expand Down

0 comments on commit e0005e8

Please sign in to comment.