@@ -7,37 +7,23 @@ const Big = require('big.js')
7
7
const CID = require ( 'cids' )
8
8
const PeerId = require ( 'peer-id' )
9
9
const errCode = require ( 'err-code' )
10
- const multibase = require ( 'multibase' )
11
- const { cidToString } = require ( '../../utils/cid' )
12
10
13
11
function formatWantlist ( list , cidBase ) {
14
- return Array . from ( list ) . map ( ( e ) => cidToString ( e [ 1 ] . cid , cidBase ) )
12
+ return Array . from ( list ) . map ( ( e ) => ( { '/' : e [ 1 ] . cid . toBaseEncodedString ( ) } ) )
15
13
}
16
14
17
15
module . exports = function bitswap ( self ) {
18
16
return {
19
- wantlist : promisify ( ( peerId , options , callback ) => {
17
+ wantlist : promisify ( ( peerId , callback ) => {
20
18
if ( typeof peerId === 'function' ) {
21
19
callback = peerId
22
- options = { }
23
20
peerId = null
24
- } else if ( typeof options === 'function' ) {
25
- callback = options
26
- options = { }
27
21
}
28
22
29
- options = options || { }
30
-
31
23
if ( ! self . isOnline ( ) ) {
32
24
return setImmediate ( ( ) => callback ( new Error ( OFFLINE_ERROR ) ) )
33
25
}
34
26
35
- if ( options . cidBase && ! multibase . names . includes ( options . cidBase ) ) {
36
- return setImmediate ( ( ) => {
37
- callback ( errCode ( new Error ( 'invalid multibase' ) , 'ERR_INVALID_MULTIBASE' ) )
38
- } )
39
- }
40
-
41
27
let list
42
28
if ( peerId ) {
43
29
try {
@@ -53,34 +39,21 @@ module.exports = function bitswap (self) {
53
39
list = self . _bitswap . getWantlist ( )
54
40
}
55
41
56
- setImmediate ( ( ) => callback ( null , formatWantlist ( list , options . cidBase ) ) )
42
+ setImmediate ( ( ) => callback ( null , formatWantlist ( list ) ) )
57
43
} ) ,
58
44
59
- stat : promisify ( ( options , callback ) => {
60
- if ( typeof options === 'function' ) {
61
- callback = options
62
- options = { }
63
- }
64
-
65
- options = options || { }
66
-
45
+ stat : promisify ( ( callback ) => {
67
46
if ( ! self . isOnline ( ) ) {
68
47
return setImmediate ( ( ) => callback ( new Error ( OFFLINE_ERROR ) ) )
69
48
}
70
49
71
- if ( options . cidBase && ! multibase . names . includes ( options . cidBase ) ) {
72
- return setImmediate ( ( ) => {
73
- callback ( errCode ( new Error ( 'invalid multibase' ) , 'ERR_INVALID_MULTIBASE' ) )
74
- } )
75
- }
76
-
77
50
const snapshot = self . _bitswap . stat ( ) . snapshot
78
51
79
52
setImmediate ( ( ) => {
80
53
callback ( null , {
81
54
provideBufLen : parseInt ( snapshot . providesBufferLength . toString ( ) ) ,
82
55
blocksReceived : new Big ( snapshot . blocksReceived ) ,
83
- wantlist : formatWantlist ( self . _bitswap . getWantlist ( ) , options . cidBase ) ,
56
+ wantlist : formatWantlist ( self . _bitswap . getWantlist ( ) ) ,
84
57
peers : self . _bitswap . peers ( ) . map ( ( id ) => id . toB58String ( ) ) ,
85
58
dupBlksReceived : new Big ( snapshot . dupBlksReceived ) ,
86
59
dupDataReceived : new Big ( snapshot . dupDataReceived ) ,
0 commit comments