Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit e7b91ff

Browse files
vmxdaviddias
authored andcommitted
refactor: remove duplicated code
The `stats bitswap` command is an alias of `bitswap stat`. That should also be reflected in the code.
1 parent d6ac355 commit e7b91ff

File tree

1 file changed

+6
-35
lines changed

1 file changed

+6
-35
lines changed

src/cli/commands/stats/bitswap.js

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,8 @@
11
'use strict'
22

3-
const CID = require('cids')
4-
const print = require('../../utils').print
5-
6-
module.exports = {
7-
command: 'bitswap',
8-
9-
describe: 'Show some diagnostic information on the bitswap agent.',
10-
11-
builder: {},
12-
13-
handler (argv) {
14-
argv.ipfs.stats.bitswap((err, stats) => {
15-
if (err) {
16-
throw err
17-
}
18-
19-
stats.wantlist = stats.wantlist || []
20-
stats.wantlist = stats.wantlist.map((entry) => {
21-
const buf = Buffer.from(entry.cid.hash.data)
22-
const cid = new CID(entry.cid.version, entry.cid.codec, buf)
23-
return cid.toBaseEncodedString()
24-
})
25-
stats.peers = stats.peers || []
26-
27-
print(`bitswap status
28-
blocks received: ${stats.blocksReceived}
29-
dup blocks received: ${stats.dupBlksReceived}
30-
dup data received: ${stats.dupDataReceived}B
31-
wantlist [${stats.wantlist.length} keys]
32-
${stats.wantlist.join('\n ')}
33-
partners [${stats.peers.length}]
34-
${stats.peers.join('\n ')}`)
35-
})
36-
}
37-
}
3+
// This is an alias for `bitswap stat`.
4+
const bitswapStats = require('../bitswap/stat.js')
5+
// The command needs to be renamed, else it would be `stats stat` instead of
6+
// `stats bitswap`
7+
bitswapStats.command = 'bitswap'
8+
module.exports = bitswapStats

0 commit comments

Comments
 (0)