Skip to content

Commit

Permalink
Merge pull request #224 from pshenmic/feat/getCreditsCount
Browse files Browse the repository at this point in the history
Add platform total credits API in the status
  • Loading branch information
pshenmic authored Sep 3, 2024
2 parents 9ed566b + d73a6be commit 7d1dbf6
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 12 deletions.
4 changes: 1 addition & 3 deletions packages/api/.env
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ DASHCORE_PORT=19998
DASHCORE_USER=username
DASHCORE_PASS=password
EPOCH_CHANGE_TIME=3600000
DAPI_HOST=127.0.0.1
DAPI_PORT=1443
DAPI_PROTOCOL=http
DAPI_URL=127.0.0.1:1443:self-signed
1 change: 1 addition & 0 deletions packages/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ HTTP /status
endTime: "2024-04-09T14:00:00.000Z"
},
identitiesCount: 12,
totalCredits: 100000,
transactionsCount: 3,
transfersCount: 0,
dataContractsCount: 1,
Expand Down
6 changes: 4 additions & 2 deletions packages/api/src/controllers/MainController.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ class MainController {
}

getStatus = async (request, response) => {
const [blocks, stats, tdStatus, genesisTime] = (await Promise.allSettled([
const [blocks, stats, tdStatus, genesisTime, totalCredits] = (await Promise.allSettled([
this.blocksDAO.getBlocks(1, 1, 'desc'),
this.blocksDAO.getStats(),
TenderdashRPC.getStatus(),
Constants.genesisTime
Constants.genesisTime,
this.dapi.getTotalCredits()
])).map((e) => e.value ?? null)

const [currentBlock] = blocks?.resultSet ?? []
Expand All @@ -42,6 +43,7 @@ class MainController {
response.send({
epoch,
transactionsCount: stats?.transactionsCount,
totalCredits,
transfersCount: stats?.transfersCount,
dataContractsCount: stats?.dataContractsCount,
documentsCount: stats?.documentsCount,
Expand Down
5 changes: 5 additions & 0 deletions packages/api/src/dapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ class DAPI {
const identity = await this.dapi.platform.getIdentity(Identifier.from(identifier))
return this.dpp.identity.createFromBuffer(identity.getIdentity()).balance
}

async getTotalCredits () {
const { totalCreditsInPlatform } = await this.dapi.platform.getTotalCreditsInPlatform()
return totalCreditsInPlatform
}
}

module.exports = DAPI
9 changes: 2 additions & 7 deletions packages/api/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,8 @@ module.exports = {
await client.platform.initialize()

const dapiClient = new DAPIClient({
dapiAddresses: [
{
host: process.env.DAPI_HOST ?? 'localhost',
port: process.env.DAPI_PORT ?? '1443',
protocol: process.env.DAPI_PROTOCOL ?? 'http'
}
]
dapiAddresses: process.env.DAPI_URL.split(','),
network: process.env.NETWORK ?? 'testnet'
})

const { dpp } = client.platform
Expand Down
5 changes: 5 additions & 0 deletions packages/api/test/integration/main.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('Other routes', () => {

before(async () => {
mock.method(DAPI.prototype, 'getIdentityBalance', async () => 0)
mock.method(DAPI.prototype, 'getTotalCredits', async () => 0)

mock.method(tenderdashRpc, 'getBlockByHeight', async () => ({
block: {
Expand Down Expand Up @@ -258,6 +259,7 @@ describe('Other routes', () => {
epoch: null,
identitiesCount: 1,
transactionsCount: 3,
totalCredits: 0,
transfersCount: 0,
dataContractsCount: 1,
documentsCount: 1,
Expand Down Expand Up @@ -312,6 +314,7 @@ describe('Other routes', () => {
epoch: null,
identitiesCount: 1,
transactionsCount: 3,
totalCredits: 0,
transfersCount: 0,
dataContractsCount: 1,
documentsCount: 1,
Expand Down Expand Up @@ -350,6 +353,7 @@ describe('Other routes', () => {
}
}
mock.reset()
mock.method(DAPI.prototype, 'getTotalCredits', async () => 0)
mock.method(tenderdashRpc, 'getStatus', async () => (mockTDStatus))
mock.method(tenderdashRpc, 'getBlockByHeight', async () => ({
block: {
Expand All @@ -371,6 +375,7 @@ describe('Other routes', () => {
},
identitiesCount: 1,
transactionsCount: 3,
totalCredits: 0,
transfersCount: 0,
dataContractsCount: 1,
documentsCount: 1,
Expand Down
1 change: 1 addition & 0 deletions packages/frontend/src/app/api/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ HTTP /status
endTime: "2024-04-09T14:00:00.000Z"
},
identitiesCount: 12,
totalCredits: 100000,
transactionsCount: 3,
transfersCount: 0,
dataContractsCount: 1,
Expand Down

0 comments on commit 7d1dbf6

Please sign in to comment.