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

Commit f41c680

Browse files
committed
feat: object API internals updated to use CID
1 parent ca59a46 commit f41c680

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

src/core/components/object.js

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
'use strict'
22

3-
const mDAG = require('ipfs-merkle-dag')
43
const waterfall = require('async/waterfall')
54
const promisify = require('promisify-es6')
65
const bs58 = require('bs58')
7-
const DAGNode = mDAG.DAGNode
8-
const DAGLink = mDAG.DAGLink
6+
const dagPB = require('ipld-dag-pb')
7+
const DAGNode = dagPB.DAGNode
8+
const DAGLink = dagPB.DAGLink
9+
const CID = require('cids')
910

1011
function normalizeMultihash (multihash, enc) {
1112
if (typeof multihash === 'string') {
@@ -49,9 +50,7 @@ function parseJSONBuffer (buf) {
4950
}
5051

5152
function parseProtoBuffer (buf) {
52-
const node = new DAGNode()
53-
node.unMarshal(buf)
54-
return node
53+
return dagPB.util.deserialize(buf)
5554
}
5655

5756
module.exports = function object (self) {
@@ -63,9 +62,16 @@ module.exports = function object (self) {
6362
}
6463

6564
waterfall([
66-
(cb) => self.object.get(multihash, options, cb),
65+
(cb) => {
66+
self.object.get(multihash, options, cb)
67+
},
6768
(node, cb) => {
68-
self._dagService.put(edit(node), (err) => {
69+
node = edit(node)
70+
71+
self._ipldResolver.put({
72+
node: node,
73+
cid: new CID(node.multihash())
74+
}, (err) => {
6975
cb(err, node)
7076
})
7177
}
@@ -77,15 +83,17 @@ module.exports = function object (self) {
7783
new: promisify((cb) => {
7884
const node = new DAGNode()
7985

80-
self._dagService.put(node, function (err) {
86+
self._ipldResolver.put({
87+
node: node,
88+
cid: new CID(node.multihash())
89+
}, function (err) {
8190
if (err) {
8291
return cb(err)
8392
}
8493

8594
cb(null, node)
8695
})
8796
}),
88-
8997
put: promisify((obj, options, cb) => {
9098
if (typeof options === 'function') {
9199
cb = options
@@ -114,7 +122,10 @@ module.exports = function object (self) {
114122
return cb(new Error('obj not recognized'))
115123
}
116124

117-
self._dagService.put(node, (err, block) => {
125+
self._ipldResolver.put({
126+
node: node,
127+
cid: new CID(node.multihash())
128+
}, (err, block) => {
118129
if (err) {
119130
return cb(err)
120131
}
@@ -136,8 +147,8 @@ module.exports = function object (self) {
136147
} catch (err) {
137148
return cb(err)
138149
}
139-
140-
self._dagService.get(mh, cb)
150+
const cid = new CID(mh)
151+
self._ipldResolver.get(cid, cb)
141152
}),
142153

143154
data: promisify((multihash, options, cb) => {
@@ -180,7 +191,7 @@ module.exports = function object (self) {
180191
return cb(err)
181192
}
182193

183-
const blockSize = node.marshal().length
194+
const blockSize = dagPB.util.serialize(node).length
184195
const linkLength = node.links.reduce((a, l) => a + l.size, 0)
185196

186197
cb(null, {

src/core/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
'use strict'
22

33
const BlockService = require('ipfs-block-service')
4-
const mDAG = require('ipfs-merkle-dag')
5-
const DAGService = mDAG.DAGService
4+
const IPLDResolver = require('ipld-resolver')
65
const PeerBook = require('peer-book')
76

87
const defaultRepo = require('./default-repo')
@@ -44,7 +43,7 @@ function IPFS (repoInstance) {
4443
this._libp2pNode = null
4544
this._bitswap = null
4645
this._blockService = new BlockService(this._repo)
47-
this._dagService = new DAGService(this._blockService)
46+
this._ipldResolver = new IPLDResolver(this._blockService)
4847

4948
// IPFS Core exposed components
5049

test/core/both/test-block.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,4 @@ const common = {
1717
}
1818
}
1919

20-
console.log('->')
2120
test.block(common)

0 commit comments

Comments
 (0)