@@ -46,14 +46,17 @@ module.exports = (send) => {
46
46
return callback ( err )
47
47
}
48
48
49
- const node = new DAGNode ( result . Data , result . Links . map (
50
- ( l ) => {
51
- return new DAGLink ( l . Name , l . Size , new Buffer ( bs58 . decode ( l . Hash ) ) )
52
- } ) )
53
-
54
- cache . set ( multihash , node )
49
+ const links = result . Links . map ( ( l ) => {
50
+ return new DAGLink ( l . Name , l . Size , new Buffer ( bs58 . decode ( l . Hash ) ) )
51
+ } )
55
52
56
- callback ( null , node )
53
+ DAGNode . create ( result . Data , links , ( err , node ) => {
54
+ if ( err ) {
55
+ return callback ( err )
56
+ }
57
+ cache . set ( multihash , node )
58
+ callback ( null , node )
59
+ } )
57
60
} )
58
61
} ) ,
59
62
@@ -125,23 +128,26 @@ module.exports = (send) => {
125
128
} )
126
129
return
127
130
} else {
128
- node = new DAGNode ( obj . Data , obj . Links )
129
- }
130
- next ( )
131
-
132
- function next ( ) {
133
- node . toJSON ( ( err , nodeJSON ) => {
131
+ DAGNode . create ( obj . Data , obj . Links , ( err , _node ) => {
134
132
if ( err ) {
135
133
return callback ( err )
136
134
}
137
- if ( nodeJSON . Hash !== result . Hash ) {
138
- return callback ( new Error ( 'Stored object was different from constructed object' ) )
139
- }
135
+ node = _node
136
+ next ( )
137
+ } )
138
+ return
139
+ }
140
+ next ( )
140
141
141
- cache . set ( result . Hash , node )
142
+ function next ( ) {
143
+ const nodeJSON = node . toJSON ( )
144
+ if ( nodeJSON . multihash !== result . Hash ) {
145
+ const err = new Error ( 'multihashes do not match' )
146
+ return callback ( err )
147
+ }
142
148
143
- callback ( null , node )
144
- } )
149
+ cache . set ( result . Hash , node )
150
+ callback ( null , node )
145
151
}
146
152
} )
147
153
} ) ,
@@ -248,14 +254,13 @@ module.exports = (send) => {
248
254
return callback ( err )
249
255
}
250
256
251
- const node = new DAGNode ( )
252
- node . toJSON ( ( err , nodeJSON ) => {
257
+ DAGNode . create ( new Buffer ( 0 ) , ( err , node ) => {
253
258
if ( err ) {
254
259
return callback ( err )
255
260
}
256
261
257
- if ( nodeJSON . Hash !== result . Hash ) {
258
- return callback ( new Error ( 'Stored object was different from constructed object ' ) )
262
+ if ( node . toJSON . multihash !== result . Hash ) {
263
+ return callback ( new Error ( 'multihahes do not match ' ) )
259
264
}
260
265
261
266
callback ( null , node )
0 commit comments