UNPKG

kubo-rpc-client

Version:
27 lines 1.06 kB
import { peerIdFromString } from '@libp2p/peer-id'; import { CID } from 'multiformats/cid'; import { toUrlSearchParams } from '../lib/to-url-search-params.js'; export function createStat(client) { return async function stat(options = {}) { const res = await client.post('bitswap/stat', { searchParams: toUrlSearchParams(options), signal: options.signal, headers: options.headers }); return toCoreInterface(await res.json()); }; } function toCoreInterface(res) { return { provideBufLen: res.ProvideBufLen, wantlist: (res.Wantlist ?? []).map((k) => CID.parse(k['/'])), peers: (res.Peers ?? []).map((str) => peerIdFromString(str)), blocksReceived: BigInt(res.BlocksReceived), dataReceived: BigInt(res.DataReceived), blocksSent: BigInt(res.BlocksSent), dataSent: BigInt(res.DataSent), dupBlksReceived: BigInt(res.DupBlksReceived), dupDataReceived: BigInt(res.DupDataReceived) }; } //# sourceMappingURL=stat.js.map