This repository was archived by the owner on Mar 10, 2020. It is now read-only.
File tree 2 files changed +13
-41
lines changed
2 files changed +13
-41
lines changed Original file line number Diff line number Diff line change @@ -4,33 +4,21 @@ const promisify = require('promisify-es6')
4
4
const CID = require ( 'cids' )
5
5
6
6
module . exports = ( send ) => {
7
- return promisify ( ( args , opts , callback ) => {
7
+ return promisify ( ( cid , opts , callback ) => {
8
8
if ( typeof ( opts ) === 'function' ) {
9
9
callback = opts
10
10
opts = { }
11
11
}
12
12
13
- // Mirrors block.get's parsing of the CID
14
- let cid
15
13
try {
16
- if ( CID . isCID ( args ) ) {
17
- cid = args
18
- args = cid . toBaseEncodedString ( )
19
- } else if ( Buffer . isBuffer ( args ) ) {
20
- cid = new CID ( args )
21
- args = cid . toBaseEncodedString ( )
22
- } else if ( typeof args === 'string' ) {
23
- cid = new CID ( args )
24
- } else {
25
- return callback ( new Error ( 'invalid argument' ) )
26
- }
14
+ cid = new CID ( cid )
27
15
} catch ( err ) {
28
16
return callback ( err )
29
17
}
30
18
31
19
send ( {
32
20
path : 'bitswap/unwant' ,
33
- args : args ,
21
+ args : cid . toBaseEncodedString ( ) ,
34
22
qs : opts
35
23
} , callback )
36
24
} )
Original file line number Diff line number Diff line change @@ -4,42 +4,26 @@ const promisify = require('promisify-es6')
4
4
const CID = require ( 'cids' )
5
5
6
6
module . exports = ( send ) => {
7
- return promisify ( ( args , opts , callback ) => {
8
-
9
- if ( typeof ( args ) === 'function' ) {
10
- callback = args
7
+ return promisify ( ( peerId , opts , callback ) => {
8
+ if ( typeof ( peerId ) === 'function' ) {
9
+ callback = peerId
10
+ opts = { }
11
+ peerId = null
12
+ } else if ( typeof ( opts ) === 'function' ) {
13
+ callback = opts
11
14
opts = { }
12
- args = null
13
- } else {
14
- if ( typeof ( opts ) === 'function' ) {
15
- callback = opts
16
- opts = { }
17
- }
18
15
}
19
16
20
- // Mirrors block.get's parsing of the CID
21
- let cid
22
- if ( args ) {
17
+ if ( peerId ) {
23
18
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
- }
19
+ opts . peer = new CID ( peerId ) . toBaseEncodedString ( )
35
20
} catch ( err ) {
36
21
return callback ( err )
37
22
}
38
- opts . peer = args
39
23
}
24
+
40
25
send ( {
41
26
path : 'bitswap/wantlist' ,
42
- args : args ,
43
27
qs : opts
44
28
} , callback )
45
29
} )
You can’t perform that action at this time.
0 commit comments