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

Commit e0005e8

Browse files
committed
chore: update to js-ipld 0.19
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.
1 parent 9a82b05 commit e0005e8

File tree

4 files changed

+49
-9
lines changed

4 files changed

+49
-9
lines changed

examples/traverse-ipld-graphs/get-path-accross-formats.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ createNode((err, ipfs) => {
3636
const myData = {
3737
name: 'David',
3838
likes: ['js-ipfs', 'icecream', 'steak'],
39-
hobbies: [{ '/': cidPBNode.toBaseEncodedString() }]
39+
hobbies: [cidPBNode]
4040
}
4141

4242
ipfs.dag.put(myData, { format: 'dag-cbor', hashAlg: 'sha3-512' }, (err, cid) => {

package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"expose-loader": "~0.7.5",
7272
"form-data": "^2.3.2",
7373
"hat": "0.0.3",
74-
"interface-ipfs-core": "~0.78.0",
74+
"interface-ipfs-core": "~0.79.0",
7575
"ipfsd-ctl": "~0.39.3",
7676
"mocha": "^5.2.0",
7777
"ncp": "^2.0.0",
@@ -117,9 +117,14 @@
117117
"ipfs-repo": "~0.24.0",
118118
"ipfs-unixfs": "~0.1.15",
119119
"ipfs-unixfs-engine": "~0.32.3",
120-
"ipld": "~0.17.3",
121-
"ipld-dag-cbor": "~0.12.1",
120+
"ipld": "~0.19.0",
121+
"ipld-bitcoin": "~0.1.8",
122+
"ipld-dag-cbor": "~0.13.0",
122123
"ipld-dag-pb": "~0.14.6",
124+
"ipld-ethereum": "^2.0.1",
125+
"ipld-git": "~0.2.2",
126+
"ipld-raw": "^2.0.1",
127+
"ipld-zcash": "~0.1.6",
123128
"ipns": "~0.2.0",
124129
"is-ipfs": "~0.4.2",
125130
"is-pull-stream": "~0.0.0",

src/cli/utils.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,21 @@ const Progress = require('progress')
1111
const byteman = require('byteman')
1212
const promisify = require('promisify-es6')
1313

14+
// All known IPLD formats
15+
const ipldBitcoin = require('ipld-bitcoin')
16+
const ipldDagCbor = require('ipld-dag-cbor')
17+
const ipldDagPb = require('ipld-dag-pb')
18+
const ipldEthAccountSnapshot = require('ipld-ethereum').ethAccountSnapshot
19+
const ipldEthBlock = require('ipld-ethereum').ethBlock
20+
const ipldEthBlockList = require('ipld-ethereum').ethBlockList
21+
const ipldEthStateTrie = require('ipld-ethereum').ethStateTrie
22+
const ipldEthStorageTrie = require('ipld-ethereum').ethStorageTrie
23+
const ipldEthTrie = require('ipld-ethereum').ethTxTrie
24+
const ipldEthTx = require('ipld-ethereum').ethTx
25+
const ipldGit = require('ipld-git')
26+
const ipldRaw = require('ipld-raw')
27+
const ipldZcash = require('ipld-zcash')
28+
1429
exports = module.exports
1530

1631
exports.isDaemonOn = isDaemonOn

src/core/index.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ const BlockService = require('ipfs-block-service')
44
const Ipld = require('ipld')
55
const PeerId = require('peer-id')
66
const PeerInfo = require('peer-info')
7-
const dagCBOR = require('ipld-dag-cbor')
8-
const dagPB = require('ipld-dag-pb')
97
const crypto = require('libp2p-crypto')
108
const isIPFS = require('is-ipfs')
119
const multiaddr = require('multiaddr')
@@ -17,6 +15,21 @@ const debug = require('debug')
1715
const extend = require('deep-extend')
1816
const EventEmitter = require('events')
1917

18+
// All known IPLD formats
19+
const ipldBitcoin = require('ipld-bitcoin')
20+
const ipldDagCbor = require('ipld-dag-cbor')
21+
const ipldDagPb = require('ipld-dag-pb')
22+
const ipldEthAccountSnapshot = require('ipld-ethereum').ethAccountSnapshot
23+
const ipldEthBlock = require('ipld-ethereum').ethBlock
24+
const ipldEthBlockList = require('ipld-ethereum').ethBlockList
25+
const ipldEthStateTrie = require('ipld-ethereum').ethStateTrie
26+
const ipldEthStorageTrie = require('ipld-ethereum').ethStorageTrie
27+
const ipldEthTrie = require('ipld-ethereum').ethTxTrie
28+
const ipldEthTx = require('ipld-ethereum').ethTx
29+
const ipldGit = require('ipld-git')
30+
const ipldRaw = require('ipld-raw')
31+
const ipldZcash = require('ipld-zcash')
32+
2033
const config = require('./config')
2134
const boot = require('./boot')
2235
const components = require('./components')
@@ -75,8 +88,8 @@ class IPFS extends EventEmitter {
7588
multibase: multibase,
7689
multihash: multihash,
7790
CID: CID,
78-
dagPB: dagPB,
79-
dagCBOR: dagCBOR
91+
dagPB: ipldDagPb,
92+
dagCBOR: ipldDagCbor
8093
}
8194

8295
// IPFS Core Internals
@@ -86,7 +99,14 @@ class IPFS extends EventEmitter {
8699
this._libp2pNode = undefined
87100
this._bitswap = undefined
88101
this._blockService = new BlockService(this._repo)
89-
this._ipld = new Ipld(this._blockService)
102+
this._ipld = new Ipld({
103+
blockService: this._blockService,
104+
formats: [
105+
ipldBitcoin, ipldDagCbor, ipldDagPb, ipldEthAccountSnapshot,
106+
ipldEthBlock, ipldEthBlockList, ipldEthStateTrie, ipldEthStorageTrie,
107+
ipldEthTrie, ipldEthTx, ipldGit, ipldRaw, ipldZcash
108+
]
109+
})
90110
this._preload = preload(this)
91111
this._mfsPreload = mfsPreload(this)
92112
this._ipns = new IPNS(null, this)

0 commit comments

Comments
 (0)