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

Commit 19bb675

Browse files
vmxdaviddias
authored andcommitted
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 8e963f9 commit 19bb675

File tree

4 files changed

+50
-5
lines changed

4 files changed

+50
-5
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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"execa": "~0.10.0",
6969
"form-data": "^2.3.2",
7070
"hat": "0.0.3",
71-
"interface-ipfs-core": "~0.78.0",
71+
"interface-ipfs-core": "~0.79.0",
7272
"ipfsd-ctl": "~0.39.3",
7373
"ncp": "^2.0.0",
7474
"qs": "^6.5.2",
@@ -108,9 +108,15 @@
108108
"ipfs-repo": "~0.24.0",
109109
"ipfs-unixfs": "~0.1.15",
110110
"ipfs-unixfs-engine": "~0.32.3",
111-
"ipld": "~0.17.3",
112111
"ipld-dag-pb": "~0.14.6",
113112
"ipns": "~0.3.0",
113+
"ipld": "~0.19.0",
114+
"ipld-bitcoin": "~0.1.8",
115+
"ipld-dag-pb": "~0.14.6",
116+
"ipld-ethereum": "^2.0.1",
117+
"ipld-git": "~0.2.2",
118+
"ipld-raw": "^2.0.1",
119+
"ipld-zcash": "~0.1.6",
114120
"is-ipfs": "~0.4.2",
115121
"is-pull-stream": "~0.0.0",
116122
"is-stream": "^1.1.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: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@ const debug = require('debug')
1515
const extend = require('deep-extend')
1616
const EventEmitter = require('events')
1717

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+
1833
const config = require('./config')
1934
const boot = require('./boot')
2035
const components = require('./components')
@@ -72,7 +87,9 @@ class IPFS extends EventEmitter {
7287
multiaddr: multiaddr,
7388
multibase: multibase,
7489
multihash: multihash,
75-
CID: CID
90+
CID: CID,
91+
dagPB: ipldDagPb,
92+
dagCBOR: ipldDagCbor
7693
}
7794

7895
// IPFS Core Internals
@@ -82,7 +99,14 @@ class IPFS extends EventEmitter {
8299
this._libp2pNode = undefined
83100
this._bitswap = undefined
84101
this._blockService = new BlockService(this._repo)
85-
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+
})
86110
this._preload = preload(this)
87111
this._mfsPreload = mfsPreload(this)
88112
this._ipns = new IPNS(null, this)

0 commit comments

Comments
 (0)