UNPKG

ipfs-http-client

Version:
35 lines (30 loc) 1.06 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var cid = require('multiformats/cid'); var configure = require('../lib/configure.js'); var toUrlSearchParams = require('../lib/to-url-search-params.js'); const createStat = configure.configure(api => { async function stat(options = {}) { const res = await api.post('bitswap/stat', { searchParams: toUrlSearchParams.toUrlSearchParams(options), signal: options.signal, headers: options.headers }); return toCoreInterface(await res.json()); } return stat; }); function toCoreInterface(res) { return { provideBufLen: res.ProvideBufLen, wantlist: (res.Wantlist || []).map(k => cid.CID.parse(k['/'])), peers: res.Peers || [], blocksReceived: BigInt(res.BlocksReceived), dataReceived: BigInt(res.DataReceived), blocksSent: BigInt(res.BlocksSent), dataSent: BigInt(res.DataSent), dupBlksReceived: BigInt(res.DupBlksReceived), dupDataReceived: BigInt(res.DupDataReceived) }; } exports.createStat = createStat;