1
1
'use strict'
2
2
3
- const mDAG = require ( 'ipfs-merkle-dag' )
4
3
const waterfall = require ( 'async/waterfall' )
5
4
const promisify = require ( 'promisify-es6' )
6
5
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' )
9
10
10
11
function normalizeMultihash ( multihash , enc ) {
11
12
if ( typeof multihash === 'string' ) {
@@ -49,9 +50,7 @@ function parseJSONBuffer (buf) {
49
50
}
50
51
51
52
function parseProtoBuffer ( buf ) {
52
- const node = new DAGNode ( )
53
- node . unMarshal ( buf )
54
- return node
53
+ return dagPB . util . deserialize ( buf )
55
54
}
56
55
57
56
module . exports = function object ( self ) {
@@ -63,9 +62,16 @@ module.exports = function object (self) {
63
62
}
64
63
65
64
waterfall ( [
66
- ( cb ) => self . object . get ( multihash , options , cb ) ,
65
+ ( cb ) => {
66
+ self . object . get ( multihash , options , cb )
67
+ } ,
67
68
( 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 ) => {
69
75
cb ( err , node )
70
76
} )
71
77
}
@@ -77,15 +83,17 @@ module.exports = function object (self) {
77
83
new : promisify ( ( cb ) => {
78
84
const node = new DAGNode ( )
79
85
80
- self . _dagService . put ( node , function ( err ) {
86
+ self . _ipldResolver . put ( {
87
+ node : node ,
88
+ cid : new CID ( node . multihash ( ) )
89
+ } , function ( err ) {
81
90
if ( err ) {
82
91
return cb ( err )
83
92
}
84
93
85
94
cb ( null , node )
86
95
} )
87
96
} ) ,
88
-
89
97
put : promisify ( ( obj , options , cb ) => {
90
98
if ( typeof options === 'function' ) {
91
99
cb = options
@@ -114,7 +122,10 @@ module.exports = function object (self) {
114
122
return cb ( new Error ( 'obj not recognized' ) )
115
123
}
116
124
117
- self . _dagService . put ( node , ( err , block ) => {
125
+ self . _ipldResolver . put ( {
126
+ node : node ,
127
+ cid : new CID ( node . multihash ( ) )
128
+ } , ( err , block ) => {
118
129
if ( err ) {
119
130
return cb ( err )
120
131
}
@@ -136,8 +147,8 @@ module.exports = function object (self) {
136
147
} catch ( err ) {
137
148
return cb ( err )
138
149
}
139
-
140
- self . _dagService . get ( mh , cb )
150
+ const cid = new CID ( mh )
151
+ self . _ipldResolver . get ( cid , cb )
141
152
} ) ,
142
153
143
154
data : promisify ( ( multihash , options , cb ) => {
@@ -180,7 +191,7 @@ module.exports = function object (self) {
180
191
return cb ( err )
181
192
}
182
193
183
- const blockSize = node . marshal ( ) . length
194
+ const blockSize = dagPB . util . serialize ( node ) . length
184
195
const linkLength = node . links . reduce ( ( a , l ) => a + l . size , 0 )
185
196
186
197
cb ( null , {
0 commit comments