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

Validator By Identity Endpoint #348

Merged
merged 7 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
84 changes: 84 additions & 0 deletions packages/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Reference:
* [Blocks](#blocks)
* [Validators](#validators)
* [Validator by ProTxHash](#validator-by-protxhash)
* [Validator by Identity](#validator-by-identity)
owl352 marked this conversation as resolved.
Show resolved Hide resolved
* [Validator Blocks Statistic](#validator-stats-by-protxhash)
* [Validator Rewards Statistic](#validator-rewards-stats-by-protxhash)
* [Transaction by hash](#transaction-by-hash)
Expand Down Expand Up @@ -302,6 +303,89 @@ Get validator by ProTxHash.
```
GET /validator/F60A6BF9EC0794BB0CFD1E0F2217933F4B33EDE6FE810692BC275CA18148AEF0

{
proTxHash: "F60A6BF9EC0794BB0CFD1E0F2217933F4B33EDE6FE810692BC275CA18148AEF0",
isActive: true,
proposedBlocksAmount: 5,
lastProposedBlockHeader: {
height: 5,
timestamp: "2024-06-23T13:51:44.154Z",
hash: "7253F441FF6AEAC847F9E03672B9386E35FC8CBCFC4A7CC67557FCA10E342904",
l1LockedHeight: 1337,
appVersion: 1,
blockVersion: 13,
validator: "F60A6BF9EC0794BB0CFD1E0F2217933F4B33EDE6FE810692BC275CA18148AEF0"
},
proTxInfo: {
type: "Evo",
collateralHash: "6ce8545e25d4f03aba1527062d9583ae01827c65b234bd979aca5954c6ae3a59",
collateralIndex: 19,
collateralAddress: "yYK3Kiq36Xmf1ButkTUYb1iCNtJfSSM4KH",
operatorReward: 0,
confirmations: 214424,
state: {
version: 2,
service: "35.164.23.245:19999",
registeredHeight: 850334,
lastPaidHeight: 1064721,
consecutivePayments: 0,
PoSePenalty: 0,
PoSeRevivedHeight: 1027671,
PoSeBanHeight: -1,
revocationReason: 0,
ownerAddress: "yWrbg8HNwkogZfqKe1VW8czS9KiqdjvJtE",
votingAddress: "yWrbg8HNwkogZfqKe1VW8czS9KiqdjvJtE",
platformNodeID: "b5f25f8f70cf8d05c2d2970bdf186c994431d84e",
platformP2PPort: 36656,
platformHTTPPort: 1443,
payoutAddress: "yeRZBWYfeNE4yVUHV4ZLs83Ppn9aMRH57A",
pubKeyOperator: "b928fa4e127214ccb2b5de1660b5e371d2f3c9845077bc3900fc6aabe82ddd2e61530be3765cea15752e30fc761ab730",
}
},
identity: "8tsWRSwsTM5AXv4ViCF9gu39kzjbtfFDM6rCyL2RcFzd",
identityBalance: 0,
epochInfo: {
number: 1982,
firstBlockHeight: 31976,
firstCoreBlockHeight: 1118131,
startTime: 1728488466559,
feeMultiplier: 1,
endTime: 1728492066559
},
totalReward: 0,
epochReward: 0,
withdrawalsCount: 1,
lastWithdrawal: "01FE1F00379C66C6E3BFD81A088E57E17613EC36E4FF812458535A8ABCB84047",
lastWithdrawalTime: "2024-10-12T03:15:19.257Z",
endpoints: {
coreP2PPortStatus: {
host: '52.33.28.41',
port: 19999,
status: 'ERROR',
message: null
},
platformP2PPortStatus: {
host: '52.33.28.41',
port: 36656,
status: 'ERROR',
message: null
},
platformGrpcPortStatus: {
host: '52.33.28.41',
port: 1443,
status: 'ERROR',
message: null
}
}
}
```
---
### Validator by Identity
Get validator by Identity.
* `lastProposedBlockHeader` field is nullable
```
GET /validator/identity/8tsWRSwsTM5AXv4ViCF9gu39kzjbtfFDM6rCyL2RcFzd

{
proTxHash: "F60A6BF9EC0794BB0CFD1E0F2217933F4B33EDE6FE810692BC275CA18148AEF0",
isActive: true,
Expand Down
8 changes: 8 additions & 0 deletions packages/api/src/controllers/ValidatorsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ class ValidatorsController {
)
}

getValidatorByIdentifier = async (request, response) => {
const { identifier } = request.params

const hash = Buffer.from(base58.decode(identifier)).toString('hex')
owl352 marked this conversation as resolved.
Show resolved Hide resolved

await this.getValidatorByProTxHash({ ...request, params: { hash } }, response)
}

getValidators = async (request, response) => {
const { page = 1, limit = 10, order = 'asc', isActive = undefined } = request.query

Expand Down
13 changes: 13 additions & 0 deletions packages/api/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,19 @@ module.exports = ({
querystring: { $ref: 'paginationOptions#' }
}
},
{
path: '/validator/identity/:identifier',
method: 'GET',
handler: validatorsController.getValidatorByIdentifier,
schema: {
params: {
type: 'object',
properties: {
identifier: { $ref: 'identifier#' }
}
}
}
},
{
path: '/validator/:hash/stats',
method: 'GET',
Expand Down
94 changes: 94 additions & 0 deletions packages/api/test/integration/validators.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,100 @@ describe('Validators routes', () => {
})
})

describe('getValidatorByIdentity()', async () => {
it('should return inactive validator by identifier', async () => {
const [validator] = inactiveValidators

const identifier = base58.encode(Buffer.from(validator.pro_tx_hash, 'hex'))

const { body } = await client.get(`/validator/identity/${identifier}`)
.expect(200)
.expect('Content-Type', 'application/json; charset=utf-8')

const expectedValidator = {
proTxHash: validator.pro_tx_hash,
isActive: false,
proposedBlocksAmount: 0,
lastProposedBlockHeader: null,
proTxInfo: {
type: dashCoreRpcResponse.type,
collateralHash: dashCoreRpcResponse.collateralHash,
collateralIndex: dashCoreRpcResponse.collateralIndex,
collateralAddress: dashCoreRpcResponse.collateralAddress,
operatorReward: dashCoreRpcResponse.operatorReward,
confirmations: dashCoreRpcResponse.confirmations,
state: dashCoreRpcResponse.state
},
totalReward: 0,
epochReward: 0,
identity: identifier,
identityBalance: 0,
epochInfo: { ...fullEpochInfo },
withdrawalsCount: 5,
lastWithdrawal: transactions[transactions.length - 1].hash,
lastWithdrawalTime: timestamp.toISOString(),
endpoints
}

assert.deepEqual(body, expectedValidator)
})

it('should return active validator by identifier', async () => {
const [validator] = activeValidators

const identifier = base58.encode(Buffer.from(validator.pro_tx_hash, 'hex'))

const { body } = await client.get(`/validator/identity/${identifier}`)
.expect(200)
.expect('Content-Type', 'application/json; charset=utf-8')

const expectedValidator = {
proTxHash: validator.pro_tx_hash,
isActive: false,
proposedBlocksAmount: blocks.filter((block) => block.validator === validator.pro_tx_hash).length,
lastProposedBlockHeader: blocks
.filter((block) => block.validator === validator.pro_tx_hash)
.map((block) => BlockHeader.fromRow(block))
.map((blockHeader) => ({
hash: blockHeader.hash,
height: blockHeader.height,
timestamp: blockHeader.timestamp.toISOString(),
blockVersion: blockHeader.blockVersion,
appVersion: blockHeader.appVersion,
l1LockedHeight: blockHeader.l1LockedHeight,
validator: blockHeader.validator
}))
.toReversed()[0] ?? null,
proTxInfo: {
type: dashCoreRpcResponse.type,
collateralHash: dashCoreRpcResponse.collateralHash,
collateralIndex: dashCoreRpcResponse.collateralIndex,
collateralAddress: dashCoreRpcResponse.collateralAddress,
operatorReward: dashCoreRpcResponse.operatorReward,
confirmations: dashCoreRpcResponse.confirmations,
state: dashCoreRpcResponse.state
},
totalReward: 0,
epochReward: 0,
identity: identifier,
identityBalance: 0,
epochInfo: { ...fullEpochInfo },
withdrawalsCount: 5,
lastWithdrawal: transactions[transactions.length - 2].hash,
lastWithdrawalTime: timestamp.toISOString(),
endpoints
}

assert.deepEqual(body, expectedValidator)
})

it('should return 404 if validator not found', async () => {
await client.get('/validator/DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF')
.expect(404)
.expect('Content-Type', 'application/json; charset=utf-8')
})
})

describe('getValidators()', async () => {
describe('no filter', async () => {
it('should return default set of validators', async () => {
Expand Down
91 changes: 89 additions & 2 deletions packages/frontend/src/app/api/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Reference:
* [Blocks](#blocks)
* [Validators](#validators)
* [Validator by ProTxHash](#validator-by-protxhash)
* [Validator by Identity](#validator-by-identity)
* [Validator Blocks Statistic](#validator-stats-by-protxhash)
* [Validator Rewards Statistic](#validator-rewards-stats-by-protxhash)
* [Transaction by hash](#transaction-by-hash)
Expand Down Expand Up @@ -269,6 +270,89 @@ Get validator by ProTxHash.
```
GET /validator/F60A6BF9EC0794BB0CFD1E0F2217933F4B33EDE6FE810692BC275CA18148AEF0

{
proTxHash: "F60A6BF9EC0794BB0CFD1E0F2217933F4B33EDE6FE810692BC275CA18148AEF0",
isActive: true,
proposedBlocksAmount: 5,
lastProposedBlockHeader: {
height: 5,
timestamp: "2024-06-23T13:51:44.154Z",
hash: "7253F441FF6AEAC847F9E03672B9386E35FC8CBCFC4A7CC67557FCA10E342904",
l1LockedHeight: 1337,
appVersion: 1,
blockVersion: 13,
validator: "F60A6BF9EC0794BB0CFD1E0F2217933F4B33EDE6FE810692BC275CA18148AEF0"
},
proTxInfo: {
type: "Evo",
collateralHash: "6ce8545e25d4f03aba1527062d9583ae01827c65b234bd979aca5954c6ae3a59",
collateralIndex: 19,
collateralAddress: "yYK3Kiq36Xmf1ButkTUYb1iCNtJfSSM4KH",
operatorReward: 0,
confirmations: 214424,
state: {
version: 2,
service: "35.164.23.245:19999",
registeredHeight: 850334,
lastPaidHeight: 1064721,
consecutivePayments: 0,
PoSePenalty: 0,
PoSeRevivedHeight: 1027671,
PoSeBanHeight: -1,
revocationReason: 0,
ownerAddress: "yWrbg8HNwkogZfqKe1VW8czS9KiqdjvJtE",
votingAddress: "yWrbg8HNwkogZfqKe1VW8czS9KiqdjvJtE",
platformNodeID: "b5f25f8f70cf8d05c2d2970bdf186c994431d84e",
platformP2PPort: 36656,
platformHTTPPort: 1443,
payoutAddress: "yeRZBWYfeNE4yVUHV4ZLs83Ppn9aMRH57A",
pubKeyOperator: "b928fa4e127214ccb2b5de1660b5e371d2f3c9845077bc3900fc6aabe82ddd2e61530be3765cea15752e30fc761ab730",
}
},
identity: "8tsWRSwsTM5AXv4ViCF9gu39kzjbtfFDM6rCyL2RcFzd",
identityBalance: 0,
epochInfo: {
number: 1982,
firstBlockHeight: 31976,
firstCoreBlockHeight: 1118131,
startTime: 1728488466559,
feeMultiplier: 1,
endTime: 1728492066559
},
totalReward: 0,
epochReward: 0,
withdrawalsCount: 1,
lastWithdrawal: "01FE1F00379C66C6E3BFD81A088E57E17613EC36E4FF812458535A8ABCB84047",
lastWithdrawalTime: "2024-10-12T03:15:19.257Z",
endpoints: {
coreP2PPortStatus: {
host: '52.33.28.41',
port: 19999,
status: 'ERROR',
message: null
},
platformP2PPortStatus: {
host: '52.33.28.41',
port: 36656,
status: 'ERROR',
message: null
},
platformGrpcPortStatus: {
host: '52.33.28.41',
port: 1443,
status: 'ERROR',
message: null
}
}
}
```
---
### Validator by Identity
Get validator by Identity.
* `lastProposedBlockHeader` field is nullable
```
GET /validator/identity/8tsWRSwsTM5AXv4ViCF9gu39kzjbtfFDM6rCyL2RcFzd

{
proTxHash: "F60A6BF9EC0794BB0CFD1E0F2217933F4B33EDE6FE810692BC275CA18148AEF0",
isActive: true,
Expand Down Expand Up @@ -795,7 +879,7 @@ Status can be either `SUCCESS` or `FAIL`. In case of error tx, message will appe
* `limit` cannot be more then 100

```
GET /identities/GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec/transactions?page=1&limit=10&order=asc
GET /identity/GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec/transactions?page=1&limit=10&order=asc

{
pagination: {
Expand All @@ -815,7 +899,10 @@ GET /identities/GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec/transactions?page=1
gasUsed: 1337000,
status: "SUCCESS",
error: null,
owner: "GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec"
owner: {
identifier: "GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec",
aliases: []
}
}, ...
]
}
Expand Down