-
Notifications
You must be signed in to change notification settings - Fork 25
/
nano-network-monitor.mjs
43 lines (37 loc) · 976 Bytes
/
nano-network-monitor.mjs
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
import NanoNode, { NanoConstants } from 'nano-node-light'
import debug from 'debug'
import yargs from 'yargs'
import { hideBin } from 'yargs/helpers'
const argv = yargs(hideBin(process.argv)).argv
const log = debug('nano-network-monitor')
debug.enable('nano-network-monitor,node')
const getNetwork = (network = 'beta') => {
switch (network) {
case 'live':
return NanoConstants.NETWORK.LIVE
case 'beta':
return NanoConstants.NETWORK.BETA
case 'test':
return NanoConstants.NETWORK.TEST
default:
return NanoConstants.NETWORK.BETA
}
}
const network = getNetwork(argv.network)
const config = {
network,
requestTelemetry: argv.telemetry
}
const node = new NanoNode(config)
node.on('error', (error, address) => {
console.log(address)
console.log(error)
})
node.on('telemetry', (telemetry) => {
log(telemetry)
})
// connect to network bootstrap peers
node.connectDomain({
address: network.ADDRESS,
port: network.PORT
})