mirror of
https://github.com/Retropex/apolloapi-v2.git
synced 2025-05-28 13:02:35 +02:00
Add getMiningInfo to nodeStats.js
This commit is contained in:
parent
dbc847d4dd
commit
bffca493c0
@ -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
|
||||
|
@ -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
|
||||
]
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user