11'use strict'
22
3- const promisify = require ( 'promisify-es6 ' )
3+ const configure = require ( '../lib/configure ' )
44const Big = require ( 'bignumber.js' )
55
6- const transform = function ( res , callback ) {
7- callback ( null , {
6+ module . exports = configure ( ( { ky } ) => {
7+ return async ( options ) => {
8+ options = options || { }
9+
10+ const res = await ky . get ( 'bitswap/stat' , {
11+ timeout : options . timeout ,
12+ signal : options . signal ,
13+ headers : options . headers ,
14+ searchParams : options . searchParams
15+ } ) . json ( )
16+
17+ return toCoreInterface ( res )
18+ }
19+ } )
20+
21+ function toCoreInterface ( res ) {
22+ return {
823 provideBufLen : res . ProvideBufLen ,
924 wantlist : res . Wantlist || [ ] ,
1025 peers : res . Peers || [ ] ,
@@ -14,13 +29,5 @@ const transform = function (res, callback) {
1429 dataSent : new Big ( res . DataSent ) ,
1530 dupBlksReceived : new Big ( res . DupBlksReceived ) ,
1631 dupDataReceived : new Big ( res . DupDataReceived )
17- } )
18- }
19-
20- module . exports = ( send ) => {
21- return promisify ( ( callback ) => {
22- send . andTransform ( {
23- path : 'bitswap/stat'
24- } , transform , callback )
25- } )
32+ }
2633}
0 commit comments