Skip to content

Commit

Permalink
Merge branch 'master' into feat/validator-page
Browse files Browse the repository at this point in the history
  • Loading branch information
pshenmic authored Oct 21, 2024
2 parents 6033f09 + 87cea83 commit 510dc49
Show file tree
Hide file tree
Showing 46 changed files with 1,261 additions and 299 deletions.
9 changes: 0 additions & 9 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ jobs:
script: |
docker stop $(docker ps -f name=pe-testnet-api -q) || true
docker stop $(docker ps -f name=pe-testnet-indexer -q) || true
# docker stop $(docker ps -f name=pe-mainnet-api -q) || true
# docker stop $(docker ps -f name=pe-mainnet-indexer -q) || true
docker rm pe-testnet-api pe-testnet-indexer || true
drop_db:
Expand Down Expand Up @@ -71,9 +69,6 @@ jobs:
docker run --rm --env-file testnet.env ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:api npm run db:drop
docker run --rm --env-file testnet.env -v ./platform-explorer/packages/indexer/migrations:/migrations owl352/refinery_cli_docker ./refinery migrate -e DATABASE_URL -p /migrations
# docker run --rm --env-file production.env ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:api npm run db:drop
# docker run --rm --env-file production.env -v ./platform-explorer/packages/indexer/migrations:/migrations owl352/refinery_cli_docker ./refinery migrate -e DATABASE_URL -p /migrations

start:
runs-on: ubuntu-latest

Expand All @@ -98,7 +93,3 @@ jobs:
docker run -d -p 3005:3005 --restart always --env-file testnet.env --name pe-testnet-api ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:api
sleep 3
docker run -d --env-file testnet.env --restart always --name pe-testnet-indexer ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:indexer ./indexer
sleep 3
# docker run -d -p 3006:3005 --restart always --env-file production.env --name pe-mainnet-api ghcr.io/pshenmic/platform-explorer:api
sleep 3
# docker run -d --env-file production.env --restart always --name pe-mainnet-indexer ghcr.io/pshenmic/platform-explorer:indexer ./indexer
1 change: 1 addition & 0 deletions packages/api/.env
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ DASHCORE_USER=username
DASHCORE_PASS=password
EPOCH_CHANGE_TIME=3600000
DAPI_URL=127.0.0.1:1443:self-signed
TCP_CONNECT_TIMEOUT=400
103 changes: 79 additions & 24 deletions packages/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Reference:
* [Transactions By Identity](#transactions-by-identity)
* [Transfers by Identity](#transfers-by-identity)
* [Transactions history](#transactions-history)
* [Rate](#rates)
* [Rate](#rate)

### Status
Returns basic stats and epoch info
Expand Down Expand Up @@ -221,7 +221,7 @@ GET /blocks
Return all validators with pagination info.
* `lastProposedBlockHeader` field is nullable
* `?isActive=true` boolean can be supplied in the query params to filter by isActive field
* `limit` cannot be more then 100
* `limit` cannot be more then 100 (0 = all validators)
```
GET /validators
Expand Down Expand Up @@ -266,7 +266,22 @@ GET /validators
pubKeyOperator: "b928fa4e127214ccb2b5de1660b5e371d2f3c9845077bc3900fc6aabe82ddd2e61530be3765cea15752e30fc761ab730"
}
},
identity: "8tsWRSwsTM5AXv4ViCF9gu39kzjbtfFDM6rCyL2RcFzd"
identity: "8tsWRSwsTM5AXv4ViCF9gu39kzjbtfFDM6rCyL2RcFzd",
identityBalance: 0,
epochInfo: {
number: 1982,
firstBlockHeight: 31976,
firstCoreBlockHeight: 1118131,
startTime: 1728488466559,
feeMultiplier: 1,
endTime: 1728492066559
},
totalReward: 0,
epochReward: 0,
withdrawalsCount: null,
lastWithdrawal: null,
lastWithdrawalTime: null,
endpoints: null
}, ...
],
pagination: {
Expand Down Expand Up @@ -304,25 +319,59 @@ GET /validator/F60A6BF9EC0794BB0CFD1E0F2217933F4B33EDE6FE810692BC275CA18148AEF0
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"
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"
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
}
}
}
```
---
Expand Down Expand Up @@ -544,7 +593,8 @@ GET /identity/GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec
totalTransfers: 0,
totalDocuments: 0,
totalDataContracts: 0,
isSystem: false
isSystem: false,
aliases: ["test.dash"...]
}
```
Response codes:
Expand All @@ -570,7 +620,8 @@ GET /dpns/identity?dpns=test-name.1.dash
totalTransfers: 0,
totalDocuments: 0,
totalDataContracts: 0,
isSystem: false
isSystem: false,
aliases: []
}
```
Response codes:
Expand Down Expand Up @@ -606,7 +657,8 @@ GET /identities?page=1&limit=10&order=asc&order_by=block_height
totalTransfers: 0,
totalDocuments: 0,
totalDataContracts: 0,
isSystem: false
isSystem: false,
aliases: ["test.dash"]
}, ...
]
}
Expand Down Expand Up @@ -726,7 +778,7 @@ Response codes:
Return all transfers made by the given identity
* `limit` cannot be more then 100
```
GET /identities/GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec/transfers?page=1&limit=10&order=asc
GET /identities/GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec/transfers?page=1&limit=10&order=asc&type=1
{
pagination: {
Expand All @@ -740,6 +792,9 @@ GET /identities/GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec/transfers?page=1&li
sender: "GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec",
recipient: "GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec",
timestamp: "2024-03-18T10:13:54.150Z",
txHash: "445E6F081DEE877867816AD3EF492E2C0BD1DDCCDC9C793B23DDDAF8AEA23118",
type: 6,
blockHash: "73171E0A8DCC10C6DA501E1C70A9C1E0BD6F1F8F834C2A1E787AF19B1F361D5E"
}, ...
]
}
Expand Down
8 changes: 3 additions & 5 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@
"lint": "standard ."
},
"dependencies": {
"@dashevo/dapi-grpc": "^1.4.0",
"@dashevo/dapi-client": "^1.4.0",
"@dashevo/dashd-rpc": "^19.0.0",
"@dashevo/wasm-dpp": "^1.4.0",
"@dashevo/dapi-client": "1.4.1",
"@dashevo/dashd-rpc": "19.0.0",
"@fastify/cors": "^8.3.0",
"@scure/base": "^1.1.5",
"bs58": "^6.0.0",
"cbor": "^9.0.2",
"dash": "4.4.0-dev.8",
"dash": "4.4.1",
"dotenv": "^16.3.1",
"fastify": "^4.21.0",
"fastify-metrics": "^11.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/DAPI.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { Identifier } = require('@dashevo/wasm-dpp')
const { Identifier } = require('dash').PlatformProtocol

class DAPI {
dapi
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ let genesisTime

module.exports = {
EPOCH_CHANGE_TIME: Number(process.env.EPOCH_CHANGE_TIME),
TCP_CONNECT_TIMEOUT: Number(process.env.TCP_CONNECT_TIMEOUT),
get genesisTime () {
if (!genesisTime || isNaN(genesisTime)) {
return TenderdashRPC.getBlockByHeight(1).then((blockInfo) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/controllers/BlocksController.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class BlocksController {
const { validator } = request.params
const { page = 1, limit = 10, order = 'asc' } = request.query

const block = await this.blocksDAO.getBlocksByValidator(validator, Number(page), Number(limit), order)
const block = await this.blocksDAO.getBlocksByValidator(validator, Number(page ?? 1), Number(limit ?? 10), order)

if (!block) {
return response.status(404).send({ message: 'not found' })
Expand All @@ -33,7 +33,7 @@ class BlocksController {
getBlocks = async (request, response) => {
const { page = 1, limit = 10, order = 'asc' } = request.query

const blocks = await this.blocksDAO.getBlocks(Number(page), Number(limit), order)
const blocks = await this.blocksDAO.getBlocks(Number(page ?? 1), Number(limit ?? 10), order)

response.send(blocks)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/controllers/DataContractsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class DataContractsController {
getDataContracts = async (request, response) => {
const { page = 1, limit = 10, order = 'asc', order_by: orderBy = 'block_height' } = request.query

const dataContracts = await this.dataContractsDAO.getDataContracts(Number(page), Number(limit), order, orderBy)
const dataContracts = await this.dataContractsDAO.getDataContracts(Number(page ?? 1), Number(limit ?? 10), order, orderBy)

response.send(dataContracts)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/controllers/DocumentsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class DocumentsController {
const { identifier } = request.params
const { page = 1, limit = 10, order = 'asc' } = request.query

const documents = await this.documentsDAO.getDocumentsByDataContract(identifier, Number(page), Number(limit), order)
const documents = await this.documentsDAO.getDocumentsByDataContract(identifier, Number(page ?? 1), Number(limit ?? 10), order)

response.send(documents)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/controllers/EpochController.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class EpochController {
const { index } = request.params

try {
const [currentEpoch, nextEpoch] = await this.dapi.getEpochsInfo(2, index, true)
const [currentEpoch, nextEpoch] = await this.dapi.getEpochsInfo(2, index ?? undefined, index ? true : undefined)

const epoch = Epoch.fromObject({ ...currentEpoch, nextEpoch })

Expand Down
28 changes: 22 additions & 6 deletions packages/api/src/controllers/IdentitiesController.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const IdentitiesDAO = require('../dao/IdentitiesDAO')
const { IDENTITY_CREDIT_WITHDRAWAL } = require('../enums/StateTransitionEnum')

class IdentitiesController {
constructor (knex, dapi) {
Expand Down Expand Up @@ -37,7 +38,7 @@ class IdentitiesController {
getIdentities = async (request, response) => {
const { page = 1, limit = 10, order = 'asc', order_by: orderBy = 'block_height' } = request.query

const identities = await this.identitiesDAO.getIdentities(Number(page), Number(limit), order, orderBy)
const identities = await this.identitiesDAO.getIdentities(Number(page ?? 1), Number(limit ?? 10), order, orderBy)

const identitiesWithBalance = await Promise.all(identities.resultSet.map(async identity => {
const balance = await this.dapi.getIdentityBalance(identity.identifier)
Expand All @@ -51,7 +52,7 @@ class IdentitiesController {
const { identifier } = request.params
const { page = 1, limit = 10, order = 'asc' } = request.query

const transactions = await this.identitiesDAO.getTransactionsByIdentity(identifier, Number(page), Number(limit), order)
const transactions = await this.identitiesDAO.getTransactionsByIdentity(identifier, Number(page ?? 1), Number(limit ?? 10), order)

response.send(transactions)
}
Expand All @@ -60,7 +61,7 @@ class IdentitiesController {
const { identifier } = request.params
const { page = 1, limit = 10, order = 'asc' } = request.query

const dataContracts = await this.identitiesDAO.getDataContractsByIdentity(identifier, Number(page), Number(limit), order)
const dataContracts = await this.identitiesDAO.getDataContractsByIdentity(identifier, Number(page ?? 1), Number(limit ?? 10), order)

response.send(dataContracts)
}
Expand All @@ -69,19 +70,34 @@ class IdentitiesController {
const { identifier } = request.params
const { page = 1, limit = 10, order = 'asc' } = request.query

const documents = await this.identitiesDAO.getDocumentsByIdentity(identifier, Number(page), Number(limit), order)
const documents = await this.identitiesDAO.getDocumentsByIdentity(identifier, Number(page ?? 1), Number(limit ?? 10), order)

response.send(documents)
}

getTransfersByIdentity = async (request, response) => {
const { identifier } = request.params
const { page = 1, limit = 10, order = 'asc' } = request.query
const { page = 1, limit = 10, order = 'asc', type = undefined } = request.query

const transfers = await this.identitiesDAO.getTransfersByIdentity(identifier, Number(page), Number(limit), order)
const transfers = await this.identitiesDAO.getTransfersByIdentity(identifier, Number(page ?? 1), Number(limit ?? 10), order, type)

response.send(transfers)
}

getWithdrawalsByIdentity = async (request, response) => {
const { identifier } = request.params
const { page = 1, limit = 10, order = 'asc' } = request.query

const withdrawals = await this.identitiesDAO.getTransfersByIdentity(
identifier,
Number(page ?? 1),
Number(limit ?? 10),
order ?? 'asc',
IDENTITY_CREDIT_WITHDRAWAL
)

response.send(withdrawals)
}
}

module.exports = IdentitiesController
2 changes: 1 addition & 1 deletion packages/api/src/controllers/TransactionsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class TransactionsController {
return response.status(400).send({ message: `invalid ordering value ${order}. only 'asc' or 'desc' is valid values` })
}

const transactions = await this.transactionsDAO.getTransactions(Number(page), Number(limit), order)
const transactions = await this.transactionsDAO.getTransactions(Number(page ?? 1), Number(limit ?? 10), order)

response.send(transactions)
}
Expand Down
Loading

0 comments on commit 510dc49

Please sign in to comment.