-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnodestatus.js
More file actions
104 lines (98 loc) · 3.07 KB
/
nodestatus.js
File metadata and controls
104 lines (98 loc) · 3.07 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
const dotenv = require('dotenv');
dotenv.config();
const lib = require("./libs/servutils.js");
const perf = require("perf_hooks");
const path = require("path");
const http = require("http");
const express = require("express");
const app = express();
app.set("view engine", "ejs");
app.use(express.static("public"));
const Client = require("bitcoin-core");
const client = new Client({
username: process.env.RPC_Username,
password: process.env.RPC_Password,
port: process.env.RPC_port,
host: process.env.RPC_host
});
app.get("/", function(req, res) {
let starttime = perf.performance.now()
var nickname = process.env.nodenickname;
let v = [];
let promises = [
client
.listBanned()
.then(val => (v.banned = val))
.then(val => Promise.resolve(val)),
client
.getNetworkInfo()
.then(val => (v.network = val))
.then(val => Promise.resolve(val)),
client
.getPeerInfo()
.then(val => (v.peers = val))
.then(val => Promise.resolve(val)),
client
.getNetTotals()
.then(val => (v.nettotals = val))
.then(val => Promise.resolve(val)),
client
.upTime()
.then(val => (v.uptime = val))
.then(val => Promise.resolve(val)),
client
.getBlockchainInfo()
.then(val => (v.blockc = val))
.then(val => Promise.resolve(val)),
client
.getMempoolInfo()
.then(val => (v.mempool = val))
.then(val => Promise.resolve(val)),
client
.getMiningInfo()
.then(val => (v.mining = val))
.then(val => Promise.resolve(val))
];
Promise.all(promises)
.then(data => {
res.render("../views/index", {
nickname: nickname,
version: v.network.version,
subversion: v.network.subversion,
mining: v.mining,
localservices:
lib.decodeServices(v.network.localservices) +
" (" +
lib.formatHex(v.network.localservices) +
")",
protversion: v.network.protocolversion,
relayfee: v.network.relayfee,
uptime: lib.formatSeconds(v.uptime),
chain: v.blockc.chain,
blocks: v.blockc.blocks,
blockchainsize: lib.formatBytes(v.blockc.size_on_disk),
headers: v.blockc.headers,
difficulty: v.blockc.difficulty,
bestblockhash: lib.formatHex(v.blockc.bestblockhash),
mediantime: lib.convertEpoch(v.blockc.mediantime),
pruned: v.blockc.pruned,
segwit: v.blockc.bip9_softforks.segwit.status,
transactions: v.mempool.size,
mempoolbytes: lib.formatBytes(v.mempool.bytes),
maxmempool: lib.formatBytes(v.mempool.maxmempool),
totalbytesrecv: lib.formatBytes(v.nettotals.totalbytesrecv),
totalbytessent: lib.formatBytes(v.nettotals.totalbytessent),
peers: v.peers,
banned: v.banned,
time: (perf.performance.now() - starttime).toFixed()
});
})
.catch(err =>
res.render("../views/error", {
error: err
})
);
});
app.listen( process.env.webport, function(res, req) {
console.log( "Server running on port " + process.env.webport );
} );