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 all 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 Masternode Identifier](#validator-by-masternode-identifier)
* [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 Masternode Identifier
Get validator by Masternode 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 {
)
}

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

const proTxHash = Buffer.from(base58.decode(identifier)).toString('hex')

await this.getValidatorByProTxHash({ ...request, params: { hash: proTxHash } }, 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.getValidatorByMasternodeIdentifier,
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
86 changes: 85 additions & 1 deletion 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 Masternode Identifier](#validator-by-masternode-identifier)
* [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 Masternode Identifier
Get validator by Masternode Identity.
* `lastProposedBlockHeader` field is nullable
```
GET /validator/identity/8tsWRSwsTM5AXv4ViCF9gu39kzjbtfFDM6rCyL2RcFzd

{
proTxHash: "F60A6BF9EC0794BB0CFD1E0F2217933F4B33EDE6FE810692BC275CA18148AEF0",
isActive: true,
Expand Down Expand Up @@ -1368,8 +1452,8 @@ IDENTITY_CREATE with instantLock
"signature": "2019d90a905092dd3074da3cd42b05abe944d857fc2573e81e1d39a16ba659c00c7b38b88bee46a853c5c30deb9c2ae3abf4fbb781eec12b86a0928ca7b02ced7d",
"documentTypeName": "domain",
"indexName": "parentNameAndLabel",
"proTxHash": 'ad4e38fc81da72d61b14238ee6e5b91915554e24d725718800692d3a863c910b',
"choice": "Abstain",
"proTxHash": 'ad4e38fc81da72d61b14238ee6e5b91915554e24d725718800692d3a863c910b',
"raw": "08005b246080ba64350685fe302d3d790f5bb238cb619920d46230c844f079944a233bb2df460e72e3d59e7fe1c082ab3a5bd9445dd0dd5c4894a6d9f0d9ed9404b5000000e668c659af66aee1e72c186dde7b5b7e0a1d712a09c40d5721f622bf53c5315506646f6d61696e12706172656e744e616d65416e644c6162656c021204646173681203793031010c00412019d90a905092dd3074da3cd42b05abe944d857fc2573e81e1d39a16ba659c00c7b38b88bee46a853c5c30deb9c2ae3abf4fbb781eec12b86a0928ca7b02ced7d"
}
```
Expand Down