Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
feat(dag): proper get implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k authored and daviddias committed Apr 5, 2018
1 parent 9bf1c6c commit 7ba0343
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/dag/dag.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const dagCBOR = require('ipld-dag-cbor')
const promisify = require('promisify-es6')
const CID = require('cids')
const multihash = require('multihashes')
const block = require('./block')

function noop () {}

Expand Down Expand Up @@ -96,14 +97,28 @@ module.exports = (send) => {
}

send({
path: 'dag/get',
path: 'dag/resolve',
args: cid + '/' + path,
qs: options
}, (err, result) => {
}, (err, resolved) => {
if (err) {
return callback(err)
}
callback(undefined, {value: result})

let resolvedCid = new CID(resolved['Cid']['/'])

block(send).get(resolvedCid, (err, blk) => {
if (err) {
return callback(err)
}

if (resolvedCid.codec === 'dag-cbor') {
dagCBOR.resolver.resolve(blk, resolved['RemPath'], callback)
}
if (resolvedCid.codec === 'dag-pb') {
dagCBOR.resolver.resolve(blk, resolved['RemPath'], callback)
}
})
})
})
}
Expand Down

0 comments on commit 7ba0343

Please sign in to comment.