Add getMiningInfo to nodeStats.js

This commit is contained in:
Alex Thomas 2020-03-16 17:36:56 -04:00
parent dbc847d4dd
commit bffca493c0
2 changed files with 30 additions and 1 deletions

View File

@ -16,10 +16,16 @@ module.exports.typeDefs = `
timestamp: String!
blockCount: Int
connectionCount: Int
miningInfo: MiningInfo!
peerInfo: [PeerInfo!]
error: LoadingError
}
type MiningInfo {
difficulty: Float
networkhashps: Float
}
type PeerInfo {
addr: String
subver: String

View File

@ -11,8 +11,15 @@ module.exports = ({ define }) => {
// At this point, no error present
// Strip miningInfo of unnecessary properties
const unrefinedMiningInfo = unrefinedStats[2]
const miningInfo = {
difficulty: unrefinedMiningInfo.difficulty,
networkhashps: unrefinedMiningInfo.networkhashps
}
// Strip peerInfo of unnecessary properties
const unrefinedPeerInfo = unrefinedStats[2]
const unrefinedPeerInfo = unrefinedStats[3]
const peerInfo = unrefinedPeerInfo.map(({ addr, subver }) => ({
addr,
subver
@ -22,6 +29,7 @@ module.exports = ({ define }) => {
const stats = {
blockCount: unrefinedStats[0],
connectionCount: unrefinedStats[1],
miningInfo: miningInfo,
peerInfo: peerInfo,
error: null
}
@ -84,6 +92,20 @@ function getNodeStats () {
})
})
const getMiningInfoPromise = new Promise((resolve, reject) => {
litecoinClient.getMiningInfo((error, miningInfo) => {
if (error) {
reject(error)
} else {
try {
resolve(miningInfo)
} catch (error) {
reject(error)
}
}
})
})
const getPeerInfoPromise = new Promise((resolve, reject) => {
litecoinClient.getPeerInfo((error, peerInfo) => {
if (error) {
@ -102,6 +124,7 @@ function getNodeStats () {
[
getBlockCountPromise,
getConnectionCountPromise,
getMiningInfoPromise,
getPeerInfoPromise
]
)