Skip to content

Commit

Permalink
Merge pull request #148 from pshenmic/feat/tenderdash-block-time
Browse files Browse the repository at this point in the history
Add tenderdash block timestamp in the status
  • Loading branch information
pshenmic authored Jun 6, 2024
2 parents 3eb9c8d + cf21ede commit ada1f66
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 141 deletions.
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 ?? null,
timestamp: tdStatus?.highestBlock?.timestamp ?? null
}
}
})
}

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

0 comments on commit ada1f66

Please sign in to comment.