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

Commit 056dda2

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

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

src/bitswap/wantlist.js

+37-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,46 @@
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 (args) === 'function') {
10+
callback = args
11+
opts = {}
12+
args = null
13+
} else {
14+
if (typeof (opts) === 'function') {
15+
callback = opts
16+
opts = {}
17+
}
18+
}
19+
20+
// Mirrors block.get's parsing of the CID
21+
let cid
22+
if (args) {
23+
try {
24+
if (CID.isCID(args)) {
25+
cid = args
26+
args = cid.toBaseEncodedString()
27+
} else if (Buffer.isBuffer(args)) {
28+
cid = new CID(args)
29+
args = cid.toBaseEncodedString()
30+
} else if (typeof args === 'string') {
31+
cid = new CID(args)
32+
} else {
33+
return callback(new Error('invalid argument'))
34+
}
35+
} catch (err) {
36+
return callback(err)
37+
}
38+
opts.peer = args
39+
}
740
send({
8-
path: 'bitswap/wantlist'
41+
path: 'bitswap/wantlist',
42+
args: args,
43+
qs: opts
944
}, callback)
1045
})
1146
}

0 commit comments

Comments
 (0)