mirror of
https://github.com/Retropex/apolloapi-v2.git
synced 2025-06-02 15:32:30 +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!
|
timestamp: String!
|
||||||
blockCount: Int
|
blockCount: Int
|
||||||
connectionCount: Int
|
connectionCount: Int
|
||||||
|
miningInfo: MiningInfo!
|
||||||
peerInfo: [PeerInfo!]
|
peerInfo: [PeerInfo!]
|
||||||
error: LoadingError
|
error: LoadingError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MiningInfo {
|
||||||
|
difficulty: Float
|
||||||
|
networkhashps: Float
|
||||||
|
}
|
||||||
|
|
||||||
type PeerInfo {
|
type PeerInfo {
|
||||||
addr: String
|
addr: String
|
||||||
subver: String
|
subver: String
|
||||||
|
@ -11,8 +11,15 @@ module.exports = ({ define }) => {
|
|||||||
|
|
||||||
// At this point, no error present
|
// 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
|
// Strip peerInfo of unnecessary properties
|
||||||
const unrefinedPeerInfo = unrefinedStats[2]
|
const unrefinedPeerInfo = unrefinedStats[3]
|
||||||
const peerInfo = unrefinedPeerInfo.map(({ addr, subver }) => ({
|
const peerInfo = unrefinedPeerInfo.map(({ addr, subver }) => ({
|
||||||
addr,
|
addr,
|
||||||
subver
|
subver
|
||||||
@ -22,6 +29,7 @@ module.exports = ({ define }) => {
|
|||||||
const stats = {
|
const stats = {
|
||||||
blockCount: unrefinedStats[0],
|
blockCount: unrefinedStats[0],
|
||||||
connectionCount: unrefinedStats[1],
|
connectionCount: unrefinedStats[1],
|
||||||
|
miningInfo: miningInfo,
|
||||||
peerInfo: peerInfo,
|
peerInfo: peerInfo,
|
||||||
error: null
|
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) => {
|
const getPeerInfoPromise = new Promise((resolve, reject) => {
|
||||||
litecoinClient.getPeerInfo((error, peerInfo) => {
|
litecoinClient.getPeerInfo((error, peerInfo) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
@ -102,6 +124,7 @@ function getNodeStats () {
|
|||||||
[
|
[
|
||||||
getBlockCountPromise,
|
getBlockCountPromise,
|
||||||
getConnectionCountPromise,
|
getConnectionCountPromise,
|
||||||
|
getMiningInfoPromise,
|
||||||
getPeerInfoPromise
|
getPeerInfoPromise
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user