Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tenderdash block timestamp in the status #148

Merged
merged 3 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions packages/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Returns basic stats and epoch info
HTTP /status

{
epoch: {
epoch: {
index: 3,
startTime: "2024-04-08T14:00:00.000Z",
endTime: "2024-04-09T14:00:00.000Z"
Expand All @@ -77,11 +77,23 @@ HTTP /status
dataContractsCount: 1,
documentsCount: 1,
network: "dash-testnet-40",
tenderdashVersion: "0.14.4"
platformVersion: "v1.0.0-dev.12"
apiHeight: 420,
maxPeerHeight: 1337,
tenderdashChainHeight: 1337,
api: {
version: "1.0.0",
block: {
height: 20153,
timestamp: "2024-06-06T21:50:20.949Z"
}
}
platform: {
version: "1.0.0-dev.12"
},
tenderdash: {
version: "0.14.0-dev.6",
block: {
height: 20154,
timestamp: "2024-06-06T21:53:27.947Z"
}
}
}
```
---
Expand Down
25 changes: 20 additions & 5 deletions packages/api/src/controllers/MainController.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ const DocumentsDAO = require('../dao/DocumentsDAO')
const IdentitiesDAO = require('../dao/IdentitiesDAO')
const TenderdashRPC = require('../tenderdashRpc')

const API_VERSION = require('../../package.json').version
const PLATFORM_VERSION = '1' + require('../../package.json').dependencies.dash.substring(1)

class MainController {
constructor (knex) {
this.blocksDAO = new BlocksDAO(knex)
Expand Down Expand Up @@ -44,11 +47,23 @@ class MainController {
dataContractsCount: stats?.dataContractsCount,
documentsCount: stats?.documentsCount,
network: tdStatus?.network ?? null,
tenderdashVersion: tdStatus?.tenderdashVersion ?? null,
platformVersion: tdStatus?.platformVersion ?? null,
apiHeight: currentBlock?.header?.height ?? null,
maxPeerHeight: tdStatus?.maxPeerHeight ?? null,
tenderdashChainHeight: tdStatus?.tenderdashChainHeight ?? null
api: {
version: API_VERSION,
block: {
height: currentBlock?.header?.height,
timestamp: currentBlock?.header?.timestamp.toISOString()
}
},
platform: {
version: PLATFORM_VERSION
},
tenderdash: {
version: tdStatus?.version ?? null,
block: {
height: tdStatus?.highestBlock.height,
timestamp: tdStatus?.highestBlock.timestamp
}
}
})
}

Expand Down
16 changes: 7 additions & 9 deletions packages/api/src/tenderdashRpc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const fetch = require('node-fetch')
const ServiceNotAvailableError = require('./errors/ServiceNotAvailableError')

const PLATFORM_VERSION = '1' + require('../package.json').dependencies.dash.substring(1)
const BASE_URL = process.env.BASE_URL

const call = async (path, method, body) => {
Expand Down Expand Up @@ -80,17 +79,16 @@ class TenderdashRPC {

static async getStatus () {
const { sync_info: syncInfo, node_info: nodeInfo } = await call('status', 'GET')
const { latest_block_height: tenderdashChainHeight, max_peer_block_height: maxPeerHeight } = syncInfo
const { network } = nodeInfo

const tenderdashVersion = nodeInfo.version
const { latest_block_height: latestBlockHeight, latest_block_time: latestBlockTime } = syncInfo
const { network, version } = nodeInfo

return {
network,
tenderdashVersion,
platformVersion: PLATFORM_VERSION,
maxPeerHeight,
tenderdashChainHeight
version,
highestBlock: {
height: parseInt(latestBlockHeight),
timestamp: latestBlockTime
}
}
}

Expand Down
Loading
Loading