Skip to content

Instantly share code, notes, and snippets.

@pinheadmz
Created January 28, 2022 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pinheadmz/511366098265b7813053764b5adebcfb to your computer and use it in GitHub Desktop.
Save pinheadmz/511366098265b7813053764b5adebcfb to your computer and use it in GitHub Desktop.
'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