Created
January 28, 2022 19:00
-
-
Save pinheadmz/511366098265b7813053764b5adebcfb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const {NodeClient} = require('hs-client'); | |
const {Network} = require('hsd'); | |
const network = Network.get('main'); | |
const clientOptions = { | |
network: network.type, | |
port: network.rpcPort | |
} | |
const client = new NodeClient(clientOptions); | |
(async () => { | |
const result = await client.execute('getpeerinfo'); | |
let mapi = new Map(); | |
let mapo = new Map(); | |
let totali = 0; | |
let totalo = 0; | |
for (const peer of result) { | |
const subv = peer.subver; | |
const map = peer.inbound ? mapi : mapo; | |
if (peer.inbound) | |
totali++; | |
else | |
totalo++; | |
const current = map.get(subv); | |
if (!current) { | |
map.set(subv, 1); | |
} else { | |
map.set(subv, current + 1); | |
} | |
} | |
const mapilist = new Map([...mapi.entries()].sort((a, b) => (a > b ? 1 : -1) )); | |
const mapolist = new Map([...mapo.entries()].sort((a, b) => (a > b ? 1 : -1) )); | |
console.log(`INBOUND (${totali}):`, mapilist); | |
console.log(`OUTBOUND (${totalo}):`, mapolist); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment