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

Commit cf287b3

Browse files
committed
feat: pass on IPLD options
It is now possible to pass in options for IPLD. This makes it possible to pass in the formats that IPFS should support. With version 0.19.0 of js-ipld the default formats are *only* [dag-cbor] and [dag-pb]. BREAKING CHANGE: js-ipfs supports dag-cbor and dag-pb by default only If you use js-ipfs as a library, only [dag-cbor] and [dag-pb] are bundled by default. If you want to use additional formats, you need to pass them into the constructor. This example code shows how to get the same behaviour as before: ```js 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 node = new IPFS({ ipld: { formats: [ ipldBitcoin, ipldDagCbor, ipldDagPb, ipldEthAccountSnapshot, ipldEthBlock, ipldEthBlockList, ipldEthStateTrie, ipldEthStorageTrie, ipldEthTrie, ipldEthTx, ipldGit, ipldRaw, ipldZcash ] } }) ``` There is no change on the js-ipfs command line tool, it still supports all those formats. [dag-cbor]: https://github.com/ipld/js-ipld-dag-cbor [dag-pb]: https://github.com/ipld/js-ipld-dag-pp
1 parent 9a82b05 commit cf287b3

File tree

5 files changed

+45
-4
lines changed

5 files changed

+45
-4
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,14 @@ Configure remote preload nodes. The remote will preload content added on this no
295295
- `enabled` (boolean): Enable content preloading (Default: `true`)
296296
- `addresses` (array): Multiaddr API addresses of nodes that should preload content. **NOTE:** nodes specified here should also be added to your node's bootstrap address list at [`config.Boostrap`](#optionsconfig).
297297

298+
##### `options.ipld`
299+
300+
| Type | Default |
301+
|------|---------|
302+
| object | `{ blockService: ...}` |
303+
304+
Pass options into [IPLD](https://github.com/ipld/js-ipld). It can be used to pass in [IPLD formats](https://github.com/ipld/interface-ipld-format) that are not the default ones [`dag-cbor`](https://github.com/ipld/js-ipld-dag-cbor) and [`dag-pb`](https://github.com/ipld/js-ipld-dag-pb). For more information see the [js-ipld readmel](https://github.com/ipld/js-ipld#readme).
305+
298306
##### `options.EXPERIMENTAL`
299307

300308
| Type | Default |

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: 2 additions & 2 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,7 +117,7 @@
117117
"ipfs-repo": "~0.24.0",
118118
"ipfs-unixfs": "~0.1.15",
119119
"ipfs-unixfs-engine": "~0.32.3",
120-
"ipld": "~0.17.3",
120+
"ipld": "~0.19.0",
121121
"ipld-dag-cbor": "~0.12.1",
122122
"ipld-dag-pb": "~0.14.6",
123123
"ipns": "~0.2.0",

src/cli/utils.js

Lines changed: 22 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
@@ -53,6 +68,13 @@ exports.getIPFS = (argv, callback) => {
5368
pass: argv.pass,
5469
EXPERIMENTAL: {
5570
pubsub: true
71+
},
72+
ipld: {
73+
formats: [
74+
ipldBitcoin, ipldDagCbor, ipldDagPb, ipldEthAccountSnapshot,
75+
ipldEthBlock, ipldEthBlockList, ipldEthStateTrie, ipldEthStorageTrie,
76+
ipldEthTrie, ipldEthTx, ipldGit, ipldRaw, ipldZcash
77+
]
5678
}
5779
})
5880

src/core/index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,18 @@ class IPFS extends EventEmitter {
8686
this._libp2pNode = undefined
8787
this._bitswap = undefined
8888
this._blockService = new BlockService(this._repo)
89-
this._ipld = new Ipld(this._blockService)
89+
90+
// Make sure IPLD has the correct BlockService
91+
const ipldDefaults = {
92+
blockService: this._blockService
93+
}
94+
if (this._options.ipld === undefined) {
95+
this._options.ipld = ipldDefaults
96+
} else if (this._options.ipld.blockService === undefined) {
97+
this._options.ipld.blockService = ipldDefaults.blockService
98+
}
99+
this._ipld = new Ipld(this._options.ipld)
100+
90101
this._preload = preload(this)
91102
this._mfsPreload = mfsPreload(this)
92103
this._ipns = new IPNS(null, this)

0 commit comments

Comments
 (0)