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

Feat/block api update #873

Merged
merged 3 commits into from
May 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 50 additions & 39 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"devDependencies": {
"aegir": "^11.0.2",
"buffer-loader": "0.0.1",
"chai": "^3.5.0",
"chai": "^4.0.0",
"delay": "^2.0.0",
"detect-node": "^2.0.3",
"dir-compare": "^1.4.0",
Expand All @@ -72,11 +72,11 @@
"expose-loader": "^0.7.3",
"form-data": "^2.1.4",
"gulp": "^3.9.1",
"interface-ipfs-core": "~0.27.2",
"interface-ipfs-core": "~0.28.0",
"ipfsd-ctl": "~0.21.0",
"left-pad": "^1.1.3",
"lodash": "^4.17.4",
"mocha": "^3.4.1",
"mocha": "^3.4.2",
"ncp": "^2.0.0",
"nexpect": "^0.5.0",
"pre-commit": "^1.2.2",
Expand All @@ -90,7 +90,7 @@
"dependencies": {
"async": "^2.4.1",
"bl": "^1.2.1",
"boom": "^4.3.1",
"boom": "^5.1.0",
"cids": "^0.5.0",
"debug": "^2.6.8",
"fsm-event": "^2.1.0",
Expand All @@ -105,10 +105,10 @@
"ipfs-multipart": "~0.1.0",
"ipfs-repo": "~0.13.1",
"ipfs-unixfs": "~0.1.11",
"ipfs-unixfs-engine": "~0.19.1",
"ipfs-unixfs-engine": "~0.19.2",
"ipld-resolver": "~0.11.1",
"isstream": "^0.1.2",
"joi": "^10.5.0",
"joi": "^10.5.1",
"libp2p-floodsub": "~0.9.4",
"libp2p-ipfs-browser": "~0.24.1",
"libp2p-ipfs-nodejs": "~0.25.2",
Expand Down
20 changes: 17 additions & 3 deletions src/core/components/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ module.exports = function block (self) {
cid = cleanCid(cid)
self._blockService.get(cid, callback)
},
put: (block, callback) => {
put: (block, options, callback) => {
if (typeof options === 'function') {
callback = options
options = {}
}

if (Array.isArray(block)) {
return callback(new Error('Array is not supported'))
}
Expand All @@ -23,12 +28,21 @@ module.exports = function block (self) {
return cb(null, block)
}

multihashing(block, 'sha2-256', (err, multihash) => {
if (options.cid && CID.isCID(options.cid)) {
return cb(null, new Block(block, options.cid))
}

const mhtype = options.mhtype || 'sha2-256'
const format = options.format || 'dag-pb'
const cidVersion = options.version || 0
// const mhlen = options.mhlen || 0

multihashing(block, mhtype, (err, multihash) => {
if (err) {
return cb(err)
}

cb(null, new Block(block, new CID(multihash)))
cb(null, new Block(block, new CID(cidVersion, format, multihash)))
})
},
(block, cb) => self._blockService.put(block, (err) => {
Expand Down