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

Commit 3553804

Browse files
committed
feat(bitswap.wantlist) add peer parameter
1 parent 2f0bb01 commit 3553804

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

src/bitswap/wantlist.js

+29-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,38 @@
11
'use strict'
22

33
const promisify = require('promisify-es6')
4+
const CID = require('cids')
45

56
module.exports = (send) => {
6-
return promisify((callback) => {
7+
return promisify((args, opts, callback) => {
8+
9+
if (typeof (opts) === 'function') {
10+
callback = opts
11+
opts = {}
12+
}
13+
14+
// Mirrors block.get's parsing of the CID
15+
let cid
16+
if (args) {
17+
try {
18+
if (CID.isCID(args)) {
19+
cid = args
20+
args = cid.toBaseEncodedString()
21+
} else if (Buffer.isBuffer(args)) {
22+
cid = new CID(args)
23+
args = cid.toBaseEncodedString()
24+
} else if (typeof args === 'string') {
25+
cid = new CID(args)
26+
} else {
27+
return callback(new Error('invalid argument'))
28+
}
29+
} catch (err) {
30+
return callback(err)
31+
}
32+
}
733
send({
8-
path: 'bitswap/wantlist'
34+
path: 'bitswap/wantlist',
35+
args: args
936
}, callback)
1037
})
1138
}

0 commit comments

Comments
 (0)