All files / server bitswap.js

86.96% Statements 20/23
50% Branches 7/14
50% Functions 3/6
86.96% Lines 20/23

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 451x 1x 1x     39x       2x   2x 2x 2x     2x 2x     2x 2x     2x 2x     2x 2x     2x 2x       2x       2x      
import { expose } from 'postmsg-rpc'
import { post } from 'prepost'
import { isBig, bigToJson } from '../serialization/big'
 
export default function (getIpfs, opts) {
  return {
    ledger: expose('ipfs.bitswap.ledger', (...args) => getIpfs().bitswap.ledger(...args), opts),
    reprovide: expose('ipfs.bitswap.reprovide', (...args) => getIpfs().bitswap.reprovide(...args), opts),
    stat: expose('ipfs.bitswap.stat', post(
      (...args) => getIpfs().bitswap.stat(...args),
      (stats) => {
        Eif (stats) {
          Eif (isBig(stats.blocksReceived)) {
            stats.blocksReceived = bigToJson(stats.blocksReceived)
          }
 
          Eif (isBig(stats.dataReceived)) {
            stats.dataReceived = bigToJson(stats.dataReceived)
          }
 
          Eif (isBig(stats.blocksSent)) {
            stats.blocksSent = bigToJson(stats.blocksSent)
          }
 
          Eif (isBig(stats.dataSent)) {
            stats.dataSent = bigToJson(stats.dataSent)
          }
 
          Eif (isBig(stats.dupBlksReceived)) {
            stats.dupBlksReceived = bigToJson(stats.dupBlksReceived)
          }
 
          Eif (isBig(stats.dupDataReceived)) {
            stats.dupDataReceived = bigToJson(stats.dupDataReceived)
          }
        }
 
        return stats
      }
    ), opts),
    unwant: expose('ipfs.bitswap.unwant', (...args) => getIpfs().bitswap.unwant(...args), opts),
    wantlist: expose('ipfs.bitswap.wantlist', (...args) => getIpfs().bitswap.wantlist(...args), opts)
  }
}