mirror of
https://github.com/Retropex/apolloapi-v2.git
synced 2025-06-02 15:32:30 +02:00
Add getBlockchainInfoPromise to nodeStats.js
This commit is contained in:
parent
612579e725
commit
bd0974da45
@ -14,6 +14,7 @@ module.exports.typeDefs = `
|
|||||||
|
|
||||||
type NodeStats {
|
type NodeStats {
|
||||||
timestamp: String!
|
timestamp: String!
|
||||||
|
blockchainInfo: BlockchainInfo!
|
||||||
blockCount: Int
|
blockCount: Int
|
||||||
connectionCount: Int
|
connectionCount: Int
|
||||||
miningInfo: MiningInfo!
|
miningInfo: MiningInfo!
|
||||||
@ -21,6 +22,13 @@ module.exports.typeDefs = `
|
|||||||
error: LoadingError
|
error: LoadingError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type BlockchainInfo {
|
||||||
|
blocks: Int
|
||||||
|
initialBlockDownload: Boolean
|
||||||
|
medianTime: Int
|
||||||
|
verificationProgress: Float
|
||||||
|
}
|
||||||
|
|
||||||
type MiningInfo {
|
type MiningInfo {
|
||||||
difficulty: Float
|
difficulty: Float
|
||||||
networkhashps: Float
|
networkhashps: Float
|
||||||
|
@ -11,15 +11,23 @@ module.exports = ({ define }) => {
|
|||||||
|
|
||||||
// At this point, no error present
|
// At this point, no error present
|
||||||
|
|
||||||
|
const unrefinedBlockchainInfo = unrefinedStats[1];
|
||||||
|
const blockchainInfo = {
|
||||||
|
blocks: unrefinedBlockchainInfo.blocks,
|
||||||
|
initialBlockDownload: unrefinedBlockchainInfo.initialblockdownload,
|
||||||
|
medianTime: unrefinedBlockchainInfo.mediantime,
|
||||||
|
verificationProgress: unrefinedBlockchainInfo.verificationprogress
|
||||||
|
};
|
||||||
|
|
||||||
// Strip miningInfo of unnecessary properties
|
// Strip miningInfo of unnecessary properties
|
||||||
const unrefinedMiningInfo = unrefinedStats[2]
|
const unrefinedMiningInfo = unrefinedStats[3];
|
||||||
const miningInfo = {
|
const miningInfo = {
|
||||||
difficulty: unrefinedMiningInfo.difficulty,
|
difficulty: unrefinedMiningInfo.difficulty,
|
||||||
networkhashps: unrefinedMiningInfo.networkhashps
|
networkhashps: unrefinedMiningInfo.networkhashps
|
||||||
}
|
};
|
||||||
|
|
||||||
// Strip peerInfo of unnecessary properties
|
// Strip peerInfo of unnecessary properties
|
||||||
const unrefinedPeerInfo = unrefinedStats[3]
|
const unrefinedPeerInfo = unrefinedStats[4];
|
||||||
const peerInfo = unrefinedPeerInfo.map(({ addr, subver }) => ({
|
const peerInfo = unrefinedPeerInfo.map(({ addr, subver }) => ({
|
||||||
addr,
|
addr,
|
||||||
subver
|
subver
|
||||||
@ -27,27 +35,28 @@ module.exports = ({ define }) => {
|
|||||||
|
|
||||||
// Convert unrefinedStats to object
|
// Convert unrefinedStats to object
|
||||||
const stats = {
|
const stats = {
|
||||||
|
blockchainInfo: blockchainInfo,
|
||||||
blockCount: unrefinedStats[0],
|
blockCount: unrefinedStats[0],
|
||||||
connectionCount: unrefinedStats[1],
|
connectionCount: unrefinedStats[2],
|
||||||
miningInfo: miningInfo,
|
miningInfo: miningInfo,
|
||||||
peerInfo: peerInfo,
|
peerInfo: peerInfo,
|
||||||
error: null
|
error: null
|
||||||
}
|
};
|
||||||
|
|
||||||
stats.timestamp = new Date().toISOString()
|
stats.timestamp = new Date().toISOString();
|
||||||
|
|
||||||
return { stats }
|
return { stats }
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Uses errno for API not available, and use description for API loading
|
// Use errno for API not available, and use description for API loading
|
||||||
const stats = {
|
const stats = {
|
||||||
error: {
|
error: {
|
||||||
code: error.code,
|
code: error.code,
|
||||||
message: error.errno || error.message
|
message: error.errno || error.message
|
||||||
},
|
},
|
||||||
timestamp: new Date().toISOString()
|
timestamp: new Date().toISOString()
|
||||||
}
|
};
|
||||||
|
|
||||||
return { stats }
|
return { stats };
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
auth: true
|
auth: true
|
||||||
@ -78,6 +87,20 @@ function getNodeStats () {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const getBlockchainInfoPromise = new Promise((resolve, reject) => {
|
||||||
|
litecoinClient.getBlockchainInfo((error, blockchainInfo) => {
|
||||||
|
if (error) {
|
||||||
|
reject(error)
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
resolve(blockchainInfo)
|
||||||
|
} catch (error) {
|
||||||
|
reject(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
const getConnectionCountPromise = new Promise((resolve, reject) => {
|
const getConnectionCountPromise = new Promise((resolve, reject) => {
|
||||||
litecoinClient.getConnectionCount((error, connectionCount) => {
|
litecoinClient.getConnectionCount((error, connectionCount) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
@ -123,6 +146,7 @@ function getNodeStats () {
|
|||||||
return Promise.all(
|
return Promise.all(
|
||||||
[
|
[
|
||||||
getBlockCountPromise,
|
getBlockCountPromise,
|
||||||
|
getBlockchainInfoPromise,
|
||||||
getConnectionCountPromise,
|
getConnectionCountPromise,
|
||||||
getMiningInfoPromise,
|
getMiningInfoPromise,
|
||||||
getPeerInfoPromise
|
getPeerInfoPromise
|
||||||
|
Loading…
Reference in New Issue
Block a user