@@ -7,37 +7,23 @@ const Big = require('big.js')
77const CID = require ( 'cids' )
88const PeerId = require ( 'peer-id' )
99const errCode = require ( 'err-code' )
10- const multibase = require ( 'multibase' )
11- const { cidToString } = require ( '../../utils/cid' )
1210
1311function 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 ( ) } ) )
1513}
1614
1715module . exports = function bitswap ( self ) {
1816 return {
19- wantlist : promisify ( ( peerId , options , callback ) => {
17+ wantlist : promisify ( ( peerId , callback ) => {
2018 if ( typeof peerId === 'function' ) {
2119 callback = peerId
22- options = { }
2320 peerId = null
24- } else if ( typeof options === 'function' ) {
25- callback = options
26- options = { }
2721 }
2822
29- options = options || { }
30-
3123 if ( ! self . isOnline ( ) ) {
3224 return setImmediate ( ( ) => callback ( new Error ( OFFLINE_ERROR ) ) )
3325 }
3426
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-
4127 let list
4228 if ( peerId ) {
4329 try {
@@ -53,34 +39,21 @@ module.exports = function bitswap (self) {
5339 list = self . _bitswap . getWantlist ( )
5440 }
5541
56- setImmediate ( ( ) => callback ( null , formatWantlist ( list , options . cidBase ) ) )
42+ setImmediate ( ( ) => callback ( null , formatWantlist ( list ) ) )
5743 } ) ,
5844
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 ) => {
6746 if ( ! self . isOnline ( ) ) {
6847 return setImmediate ( ( ) => callback ( new Error ( OFFLINE_ERROR ) ) )
6948 }
7049
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-
7750 const snapshot = self . _bitswap . stat ( ) . snapshot
7851
7952 setImmediate ( ( ) => {
8053 callback ( null , {
8154 provideBufLen : parseInt ( snapshot . providesBufferLength . toString ( ) ) ,
8255 blocksReceived : new Big ( snapshot . blocksReceived ) ,
83- wantlist : formatWantlist ( self . _bitswap . getWantlist ( ) , options . cidBase ) ,
56+ wantlist : formatWantlist ( self . _bitswap . getWantlist ( ) ) ,
8457 peers : self . _bitswap . peers ( ) . map ( ( id ) => id . toB58String ( ) ) ,
8558 dupBlksReceived : new Big ( snapshot . dupBlksReceived ) ,
8659 dupDataReceived : new Big ( snapshot . dupDataReceived ) ,
0 commit comments