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

Commit 0c8d803

Browse files
authored
Feat/block api update (#873)
* feat: support new block.put API
1 parent 3378964 commit 0c8d803

File tree

3 files changed

+73
-48
lines changed

3 files changed

+73
-48
lines changed

package-lock.json

Lines changed: 50 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"devDependencies": {
6363
"aegir": "^11.0.2",
6464
"buffer-loader": "0.0.1",
65-
"chai": "^3.5.0",
65+
"chai": "^4.0.0",
6666
"delay": "^2.0.0",
6767
"detect-node": "^2.0.3",
6868
"dir-compare": "^1.4.0",
@@ -72,11 +72,11 @@
7272
"expose-loader": "^0.7.3",
7373
"form-data": "^2.1.4",
7474
"gulp": "^3.9.1",
75-
"interface-ipfs-core": "~0.27.2",
75+
"interface-ipfs-core": "~0.28.0",
7676
"ipfsd-ctl": "~0.21.0",
7777
"left-pad": "^1.1.3",
7878
"lodash": "^4.17.4",
79-
"mocha": "^3.4.1",
79+
"mocha": "^3.4.2",
8080
"ncp": "^2.0.0",
8181
"nexpect": "^0.5.0",
8282
"pre-commit": "^1.2.2",
@@ -90,7 +90,7 @@
9090
"dependencies": {
9191
"async": "^2.4.1",
9292
"bl": "^1.2.1",
93-
"boom": "^4.3.1",
93+
"boom": "^5.1.0",
9494
"cids": "^0.5.0",
9595
"debug": "^2.6.8",
9696
"fsm-event": "^2.1.0",
@@ -105,10 +105,10 @@
105105
"ipfs-multipart": "~0.1.0",
106106
"ipfs-repo": "~0.13.1",
107107
"ipfs-unixfs": "~0.1.11",
108-
"ipfs-unixfs-engine": "~0.19.1",
108+
"ipfs-unixfs-engine": "~0.19.2",
109109
"ipld-resolver": "~0.11.1",
110110
"isstream": "^0.1.2",
111-
"joi": "^10.5.0",
111+
"joi": "^10.5.1",
112112
"libp2p-floodsub": "~0.9.4",
113113
"libp2p-ipfs-browser": "~0.24.1",
114114
"libp2p-ipfs-nodejs": "~0.25.2",

src/core/components/block.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ module.exports = function block (self) {
1212
cid = cleanCid(cid)
1313
self._blockService.get(cid, callback)
1414
},
15-
put: (block, callback) => {
15+
put: (block, options, callback) => {
16+
if (typeof options === 'function') {
17+
callback = options
18+
options = {}
19+
}
20+
1621
if (Array.isArray(block)) {
1722
return callback(new Error('Array is not supported'))
1823
}
@@ -23,12 +28,21 @@ module.exports = function block (self) {
2328
return cb(null, block)
2429
}
2530

26-
multihashing(block, 'sha2-256', (err, multihash) => {
31+
if (options.cid && CID.isCID(options.cid)) {
32+
return cb(null, new Block(block, options.cid))
33+
}
34+
35+
const mhtype = options.mhtype || 'sha2-256'
36+
const format = options.format || 'dag-pb'
37+
const cidVersion = options.version || 0
38+
// const mhlen = options.mhlen || 0
39+
40+
multihashing(block, mhtype, (err, multihash) => {
2741
if (err) {
2842
return cb(err)
2943
}
3044

31-
cb(null, new Block(block, new CID(multihash)))
45+
cb(null, new Block(block, new CID(cidVersion, format, multihash)))
3246
})
3347
},
3448
(block, cb) => self._blockService.put(block, (err) => {

0 commit comments

Comments
 (0)