From 62bf8bfb550ccdc2fb5ef2bee520f5a3ecad1bc9 Mon Sep 17 00:00:00 2001 From: owl352 Date: Wed, 27 Nov 2024 23:49:15 +0300 Subject: [PATCH 1/5] initial fix --- packages/api/README.md | 36 ++--------- .../src/controllers/IdentitiesController.js | 59 ++++++++++++------- packages/api/src/dao/IdentitiesDAO.js | 2 +- packages/api/src/server.js | 22 +++---- packages/api/src/utils.js | 22 ++++--- .../api/test/integration/identities.spec.js | 13 +++- packages/frontend/src/app/api/content.md | 36 ++--------- 7 files changed, 84 insertions(+), 106 deletions(-) diff --git a/packages/api/README.md b/packages/api/README.md index 714924e8a..bc661792c 100644 --- a/packages/api/README.md +++ b/packages/api/README.md @@ -734,40 +734,14 @@ GET /identity/A1rgGVjRGuznRThdAA316VEEpKuVQ7mV8mBK1BFJvXnb/withdrawals?limit=5 }, resultSet: [ { - "timestamp": 1729096625509, + "document": "95eiiqMotMvH23f6cv3BPC4ykcHFWTy2g3baCTWZANAs", "sender": "A1rgGVjRGuznRThdAA316VEEpKuVQ7mV8mBK1BFJvXnb", - "id": "95eiiqMotMvH23f6cv3BPC4ykcHFWTy2g3baCTWZANAs", + "status": "COMPLETE", "amount": 200000, - "status": 3 + "withdrawalAddress": "yeRZBWYfeNE4yVUHV4ZLs83Ppn9aMRH57A", + "hash": "113F86F4D1F48159B0D6690F3C5F8F33E39243086C041CF016454A66AD63F025" }, - { - "timestamp": 1729096140465, - "sender": "A1rgGVjRGuznRThdAA316VEEpKuVQ7mV8mBK1BFJvXnb", - "id": "DJzb8nj7JTHwnvAGEGhyFc5hHLFa5Es9WFAyS4HhhNeF", - "amount": 200000, - "status": 3 - }, - { - "timestamp": 1729096636318, - "sender": "A1rgGVjRGuznRThdAA316VEEpKuVQ7mV8mBK1BFJvXnb", - "id": "E4gbWCQgqrz9DVrzCeDKhr4PVsfp6CeL5DUAYndRVWdk", - "amount": 200000, - "status": 3 - }, - { - "timestamp": 1729096795042, - "sender": "A1rgGVjRGuznRThdAA316VEEpKuVQ7mV8mBK1BFJvXnb", - "id": "FouX2qY8Eaxj5rSBrH9uxbhAM16ozrUP4sJwdo9pL7Cr", - "amount": 200000, - "status": 3 - }, - { - "timestamp": 1729097247874, - "sender": "A1rgGVjRGuznRThdAA316VEEpKuVQ7mV8mBK1BFJvXnb", - "id": "9VEpb2aJRnCxfi3LjFXWa1zshkBPfzzHHh5yqEkgqw1t", - "amount": 200000, - "status": 3 - } + ... ] } ``` diff --git a/packages/api/src/controllers/IdentitiesController.js b/packages/api/src/controllers/IdentitiesController.js index 1468e8fba..b30e4973f 100644 --- a/packages/api/src/controllers/IdentitiesController.js +++ b/packages/api/src/controllers/IdentitiesController.js @@ -1,40 +1,42 @@ const IdentitiesDAO = require('../dao/IdentitiesDAO') -const { WITHDRAWAL_CONTRACT_TYPE } = require('../constants') +const {WITHDRAWAL_CONTRACT_TYPE} = require('../constants') const WithdrawalsContract = require('../../data_contracts/withdrawals.json') const PaginatedResultSet = require('../models/PaginatedResultSet') +const {decodeStateTransition} = require('../utils') class IdentitiesController { - constructor (knex, dapi) { + constructor(client, knex, dapi) { this.identitiesDAO = new IdentitiesDAO(knex, dapi) this.dapi = dapi + this.client = client } getIdentityByIdentifier = async (request, response) => { - const { identifier } = request.params + const {identifier} = request.params const identity = await this.identitiesDAO.getIdentityByIdentifier(identifier) if (!identity) { - return response.status(404).send({ message: 'not found' }) + return response.status(404).send({message: 'not found'}) } response.send(identity) } getIdentityByDPNSName = async (request, response) => { - const { dpns } = request.query + const {dpns} = request.query const identity = await this.identitiesDAO.getIdentityByDPNSName(dpns) if (!identity) { - return response.status(404).send({ message: 'not found' }) + return response.status(404).send({message: 'not found'}) } response.send(identity) } getIdentities = async (request, response) => { - const { page = 1, limit = 10, order = 'asc', order_by: orderBy = 'block_height' } = request.query + const {page = 1, limit = 10, order = 'asc', order_by: orderBy = 'block_height'} = request.query const identities = await this.identitiesDAO.getIdentities(Number(page ?? 1), Number(limit ?? 10), order, orderBy) @@ -42,8 +44,8 @@ class IdentitiesController { } getTransactionsByIdentity = async (request, response) => { - const { identifier } = request.params - const { page = 1, limit = 10, order = 'asc' } = request.query + const {identifier} = request.params + const {page = 1, limit = 10, order = 'asc'} = request.query const transactions = await this.identitiesDAO.getTransactionsByIdentity(identifier, Number(page ?? 1), Number(limit ?? 10), order) @@ -51,8 +53,8 @@ class IdentitiesController { } getDataContractsByIdentity = async (request, response) => { - const { identifier } = request.params - const { page = 1, limit = 10, order = 'asc' } = request.query + const {identifier} = request.params + const {page = 1, limit = 10, order = 'asc'} = request.query const dataContracts = await this.identitiesDAO.getDataContractsByIdentity(identifier, Number(page ?? 1), Number(limit ?? 10), order) @@ -60,8 +62,8 @@ class IdentitiesController { } getDocumentsByIdentity = async (request, response) => { - const { identifier } = request.params - const { page = 1, limit = 10, order = 'asc' } = request.query + const {identifier} = request.params + const {page = 1, limit = 10, order = 'asc'} = request.query const documents = await this.identitiesDAO.getDocumentsByIdentity(identifier, Number(page ?? 1), Number(limit ?? 10), order) @@ -69,8 +71,8 @@ class IdentitiesController { } getTransfersByIdentity = async (request, response) => { - const { identifier } = request.params - const { page = 1, limit = 10, order = 'asc', type = undefined } = request.query + const {identifier} = request.params + const {page = 1, limit = 10, order = 'asc', type = undefined} = request.query const transfers = await this.identitiesDAO.getTransfersByIdentity(identifier, Number(page ?? 1), Number(limit ?? 10), order, type) @@ -78,21 +80,36 @@ class IdentitiesController { } getWithdrawalsByIdentity = async (request, response) => { - const { identifier } = request.params - const { limit = 100 } = request.query + const {identifier} = request.params + const {limit = 100} = request.query const documents = await this.dapi.getDocuments(WITHDRAWAL_CONTRACT_TYPE, WithdrawalsContract, identifier, limit) + if (documents.length === 0) { + return response.status(404).send({message: 'not found'}) + } + const timestamps = documents.map(document => new Date(document.timestamp).toISOString()) const txHashes = await this.identitiesDAO.getIdentityWithdrawalsByTimestamps(identifier, timestamps) - if (documents.length === 0) { - return response.status(404).send({ message: 'not found' }) - } + const decodedTx = await Promise.all(txHashes.map(async tx => ({ + ...await decodeStateTransition(this.client, tx.data), + timestamp: tx.timestamp + }))) const resultSet = documents.map(document => ({ - ...document, + document: document.id ?? null, + sender: document.sender ?? null, + status: document.status ?? null, + timestamp: document.timestamp ?? null, + amount: document.amount ?? null, + + withdrawalAddress: + decodedTx.find( + tx=>tx.timestamp.getTime() === document.timestamp + )?.outputAddress ?? null, + hash: txHashes.find( hash => new Date(hash.timestamp).toISOString() === new Date(document.timestamp).toISOString())?.hash ?? null diff --git a/packages/api/src/dao/IdentitiesDAO.js b/packages/api/src/dao/IdentitiesDAO.js index fd302847a..96e1d5126 100644 --- a/packages/api/src/dao/IdentitiesDAO.js +++ b/packages/api/src/dao/IdentitiesDAO.js @@ -357,7 +357,7 @@ module.exports = class IdentitiesDAO { getIdentityWithdrawalsByTimestamps = async (identifier, timestamps = []) => { return this.knex('state_transitions') - .select('state_transitions.hash', 'blocks.timestamp as timestamp') + .select('state_transitions.hash', 'blocks.timestamp as timestamp', 'state_transitions.data as data') .whereIn( 'blocks.timestamp', timestamps diff --git a/packages/api/src/server.js b/packages/api/src/server.js index 691efa8db..87c899a38 100644 --- a/packages/api/src/server.js +++ b/packages/api/src/server.js @@ -13,29 +13,29 @@ const DocumentsController = require('./controllers/DocumentsController') const IdentitiesController = require('./controllers/IdentitiesController') const DataContractsController = require('./controllers/DataContractsController') const ValidatorsController = require('./controllers/ValidatorsController') -const { getKnex } = require('./utils') +const {getKnex} = require('./utils') const BlocksDAO = require('./dao/BlocksDAO') const DAPI = require('./DAPI') const RateController = require('./controllers/RateController') const DAPIClient = require('@dashevo/dapi-client') -const { default: loadWasmDpp } = require('dash').PlatformProtocol +const {default: loadWasmDpp} = require('dash').PlatformProtocol -function errorHandler (err, req, reply) { +function errorHandler(err, req, reply) { if (err instanceof ServiceNotAvailableError) { - return reply.status(503).send({ error: 'tenderdash/dashcore backend is not available' }) + return reply.status(503).send({error: 'tenderdash/dashcore backend is not available'}) } if (err?.constructor?.name === 'InvalidStateTransitionError') { const [error] = err.getErrors() - const { code, message } = error + const {code, message} = error - return reply.status(500).send({ error: message, code }) + return reply.status(500).send({error: message, code}) } console.error(err) reply.status(500) - reply.send({ error: err.message }) + reply.send({error: err.message}) } let client @@ -56,7 +56,7 @@ module.exports = { network: process.env.NETWORK ?? 'testnet' }) - const { dpp } = client.platform + const {dpp} = client.platform dapi = new DAPI(dapiClient, dpp) @@ -82,7 +82,7 @@ module.exports = { const transactionsController = new TransactionsController(client, knex, dapi) const dataContractsController = new DataContractsController(knex) const documentsController = new DocumentsController(knex) - const identitiesController = new IdentitiesController(knex, dapi) + const identitiesController = new IdentitiesController(client, knex, dapi) const validatorsController = new ValidatorsController(knex, dapi) const rateController = new RateController() @@ -105,9 +105,9 @@ module.exports = { new fastify.metrics.client.Gauge({ name: 'platform_explorer_api_block_height', help: 'The latest block height in the API', - async collect () { + async collect() { const blockDAO = new BlocksDAO(knex) - const { resultSet: [block] } = await blockDAO.getBlocks(1, 1, 'desc') + const {resultSet: [block]} = await blockDAO.getBlocks(1, 1, 'desc') this.set(block.header.height) } diff --git a/packages/api/src/utils.js b/packages/api/src/utils.js index 208fed3cb..40806aead 100644 --- a/packages/api/src/utils.js +++ b/packages/api/src/utils.js @@ -3,12 +3,12 @@ const StateTransitionEnum = require('./enums/StateTransitionEnum') const PoolingEnum = require('./enums/PoolingEnum') const DocumentActionEnum = require('./enums/DocumentActionEnum') const net = require('net') -const { TCP_CONNECT_TIMEOUT, DPNS_CONTRACT, NETWORK } = require('./constants') -const { base58 } = require('@scure/base') +const {TCP_CONNECT_TIMEOUT, DPNS_CONTRACT, NETWORK} = require('./constants') +const {base58} = require('@scure/base') const convertToHomographSafeChars = require('dash/build/utils/convertToHomographSafeChars').default const Intervals = require('./enums/IntervalsEnum') const dashcorelib = require('@dashevo/dashcore-lib') -const { InstantAssetLockProof, ChainAssetLockProof } = require('@dashevo/wasm-dpp') +const {InstantAssetLockProof, ChainAssetLockProof} = require('@dashevo/wasm-dpp') const SecurityLevelEnum = require('./enums/SecurityLevelEnum') const KeyPurposeEnum = require('./enums/KeyPurposeEnum') const KeyTypeEnum = require('./enums/KeyTypeEnum') @@ -22,7 +22,7 @@ const getKnex = () => { user: process.env.POSTGRES_USER, database: process.env.POSTGRES_DB, password: process.env.POSTGRES_PASS, - ssl: process.env.POSTGRES_SSL ? { rejectUnauthorized: false } : false + ssl: process.env.POSTGRES_SSL ? {rejectUnauthorized: false} : false } }) } @@ -246,12 +246,16 @@ const decodeStateTransition = async (client, base64) => { break } case StateTransitionEnum.IDENTITY_CREDIT_WITHDRAWAL: { - decoded.outputAddress = dashcorelib.Script(stateTransition.getOutputScript()).toAddress(NETWORK).toString() - decoded.userFeeIncrease = stateTransition.getUserFeeIncrease() + decoded.outputAddress = stateTransition.getOutputScript() + ? dashcorelib + .Script(stateTransition.getOutputScript()) + .toAddress(NETWORK) + .toString() + : null + decoded.userFeeIncrease = stateTransition.getUserFeeIncrease() decoded.identityContractNonce = Number(stateTransition.getIdentityContractNonce()) decoded.identityNonce = parseInt(stateTransition.getNonce()) - decoded.senderId = stateTransition.getIdentityId().toString() decoded.amount = parseInt(stateTransition.getAmount()) decoded.outputScript = stateTransition.getOutputScript()?.toString('hex') ?? null @@ -433,10 +437,10 @@ const getAliasInfo = async (alias, dapi) => { ] ) - return { alias, contestedState } + return {alias, contestedState} } - return { alias, contestedState: null } + return {alias, contestedState: null} } module.exports = { diff --git a/packages/api/test/integration/identities.spec.js b/packages/api/test/integration/identities.spec.js index 1fe8e435b..c10718f0e 100644 --- a/packages/api/test/integration/identities.spec.js +++ b/packages/api/test/integration/identities.spec.js @@ -253,7 +253,8 @@ describe('Identities routes', () => { const transaction = await fixtures.transaction(knex, { block_hash: block.hash, type: StateTransitionEnum.IDENTITY_CREDIT_WITHDRAWAL, - owner: identity.owner + owner: identity.owner, + data: 'BQFh0z9HiTN5e+TeiDU8fC2EPCExD20A9u/zFCSnVu59+/0AAAB0alKIAAEAAAEAAUEf89R9GPHIX5QLD/HKJ1xjd86KrnTsfAOxPMxBNDO8cJkAT5yUhcl/sGbQYoHSuNVIZcVVTVnSsYMXIyimihp3Vw==' }) transactions.push({ transaction, block }) @@ -274,7 +275,15 @@ describe('Identities routes', () => { .expect(200) .expect('Content-Type', 'application/json; charset=utf-8') - assert.deepEqual(body.resultSet, withdrawals.map(withdrawal => ({ ...withdrawal, hash: withdrawal.id }))) + assert.deepEqual(body.resultSet, withdrawals.map(withdrawal => ({ + hash: withdrawal.id, + document: withdrawal.id, + sender: withdrawal.sender, + status: withdrawal.status, + timestamp: withdrawal.timestamp, + amount: withdrawal.amount, + withdrawalAddress: null, + }))) }) it('should return 404 whe identity not exist', async () => { diff --git a/packages/frontend/src/app/api/content.md b/packages/frontend/src/app/api/content.md index 02526c394..754d6fbdf 100644 --- a/packages/frontend/src/app/api/content.md +++ b/packages/frontend/src/app/api/content.md @@ -701,40 +701,14 @@ GET /identity/A1rgGVjRGuznRThdAA316VEEpKuVQ7mV8mBK1BFJvXnb/withdrawals?limit=5 }, resultSet: [ { - "timestamp": 1729096625509, + "document": "95eiiqMotMvH23f6cv3BPC4ykcHFWTy2g3baCTWZANAs", "sender": "A1rgGVjRGuznRThdAA316VEEpKuVQ7mV8mBK1BFJvXnb", - "id": "95eiiqMotMvH23f6cv3BPC4ykcHFWTy2g3baCTWZANAs", + "status": "COMPLETE", "amount": 200000, - "status": 3 + "withdrawalAddress": "yeRZBWYfeNE4yVUHV4ZLs83Ppn9aMRH57A", + "hash": "113F86F4D1F48159B0D6690F3C5F8F33E39243086C041CF016454A66AD63F025" }, - { - "timestamp": 1729096140465, - "sender": "A1rgGVjRGuznRThdAA316VEEpKuVQ7mV8mBK1BFJvXnb", - "id": "DJzb8nj7JTHwnvAGEGhyFc5hHLFa5Es9WFAyS4HhhNeF", - "amount": 200000, - "status": 3 - }, - { - "timestamp": 1729096636318, - "sender": "A1rgGVjRGuznRThdAA316VEEpKuVQ7mV8mBK1BFJvXnb", - "id": "E4gbWCQgqrz9DVrzCeDKhr4PVsfp6CeL5DUAYndRVWdk", - "amount": 200000, - "status": 3 - }, - { - "timestamp": 1729096795042, - "sender": "A1rgGVjRGuznRThdAA316VEEpKuVQ7mV8mBK1BFJvXnb", - "id": "FouX2qY8Eaxj5rSBrH9uxbhAM16ozrUP4sJwdo9pL7Cr", - "amount": 200000, - "status": 3 - }, - { - "timestamp": 1729097247874, - "sender": "A1rgGVjRGuznRThdAA316VEEpKuVQ7mV8mBK1BFJvXnb", - "id": "9VEpb2aJRnCxfi3LjFXWa1zshkBPfzzHHh5yqEkgqw1t", - "amount": 200000, - "status": 3 - } + ... ] } ``` From 74f92547c6230bb243aaa3ba9de911b006da10b8 Mon Sep 17 00:00:00 2001 From: owl352 Date: Wed, 27 Nov 2024 23:49:40 +0300 Subject: [PATCH 2/5] lint --- .../src/controllers/IdentitiesController.js | 40 +++++++++---------- packages/api/src/server.js | 20 +++++----- packages/api/src/utils.js | 12 +++--- .../api/test/integration/identities.spec.js | 2 +- 4 files changed, 37 insertions(+), 37 deletions(-) diff --git a/packages/api/src/controllers/IdentitiesController.js b/packages/api/src/controllers/IdentitiesController.js index b30e4973f..14c837523 100644 --- a/packages/api/src/controllers/IdentitiesController.js +++ b/packages/api/src/controllers/IdentitiesController.js @@ -1,42 +1,42 @@ const IdentitiesDAO = require('../dao/IdentitiesDAO') -const {WITHDRAWAL_CONTRACT_TYPE} = require('../constants') +const { WITHDRAWAL_CONTRACT_TYPE } = require('../constants') const WithdrawalsContract = require('../../data_contracts/withdrawals.json') const PaginatedResultSet = require('../models/PaginatedResultSet') -const {decodeStateTransition} = require('../utils') +const { decodeStateTransition } = require('../utils') class IdentitiesController { - constructor(client, knex, dapi) { + constructor (client, knex, dapi) { this.identitiesDAO = new IdentitiesDAO(knex, dapi) this.dapi = dapi this.client = client } getIdentityByIdentifier = async (request, response) => { - const {identifier} = request.params + const { identifier } = request.params const identity = await this.identitiesDAO.getIdentityByIdentifier(identifier) if (!identity) { - return response.status(404).send({message: 'not found'}) + return response.status(404).send({ message: 'not found' }) } response.send(identity) } getIdentityByDPNSName = async (request, response) => { - const {dpns} = request.query + const { dpns } = request.query const identity = await this.identitiesDAO.getIdentityByDPNSName(dpns) if (!identity) { - return response.status(404).send({message: 'not found'}) + return response.status(404).send({ message: 'not found' }) } response.send(identity) } getIdentities = async (request, response) => { - const {page = 1, limit = 10, order = 'asc', order_by: orderBy = 'block_height'} = request.query + const { page = 1, limit = 10, order = 'asc', order_by: orderBy = 'block_height' } = request.query const identities = await this.identitiesDAO.getIdentities(Number(page ?? 1), Number(limit ?? 10), order, orderBy) @@ -44,8 +44,8 @@ class IdentitiesController { } getTransactionsByIdentity = async (request, response) => { - const {identifier} = request.params - const {page = 1, limit = 10, order = 'asc'} = request.query + const { identifier } = request.params + const { page = 1, limit = 10, order = 'asc' } = request.query const transactions = await this.identitiesDAO.getTransactionsByIdentity(identifier, Number(page ?? 1), Number(limit ?? 10), order) @@ -53,8 +53,8 @@ class IdentitiesController { } getDataContractsByIdentity = async (request, response) => { - const {identifier} = request.params - const {page = 1, limit = 10, order = 'asc'} = request.query + const { identifier } = request.params + const { page = 1, limit = 10, order = 'asc' } = request.query const dataContracts = await this.identitiesDAO.getDataContractsByIdentity(identifier, Number(page ?? 1), Number(limit ?? 10), order) @@ -62,8 +62,8 @@ class IdentitiesController { } getDocumentsByIdentity = async (request, response) => { - const {identifier} = request.params - const {page = 1, limit = 10, order = 'asc'} = request.query + const { identifier } = request.params + const { page = 1, limit = 10, order = 'asc' } = request.query const documents = await this.identitiesDAO.getDocumentsByIdentity(identifier, Number(page ?? 1), Number(limit ?? 10), order) @@ -71,8 +71,8 @@ class IdentitiesController { } getTransfersByIdentity = async (request, response) => { - const {identifier} = request.params - const {page = 1, limit = 10, order = 'asc', type = undefined} = request.query + const { identifier } = request.params + const { page = 1, limit = 10, order = 'asc', type = undefined } = request.query const transfers = await this.identitiesDAO.getTransfersByIdentity(identifier, Number(page ?? 1), Number(limit ?? 10), order, type) @@ -80,13 +80,13 @@ class IdentitiesController { } getWithdrawalsByIdentity = async (request, response) => { - const {identifier} = request.params - const {limit = 100} = request.query + const { identifier } = request.params + const { limit = 100 } = request.query const documents = await this.dapi.getDocuments(WITHDRAWAL_CONTRACT_TYPE, WithdrawalsContract, identifier, limit) if (documents.length === 0) { - return response.status(404).send({message: 'not found'}) + return response.status(404).send({ message: 'not found' }) } const timestamps = documents.map(document => new Date(document.timestamp).toISOString()) @@ -107,7 +107,7 @@ class IdentitiesController { withdrawalAddress: decodedTx.find( - tx=>tx.timestamp.getTime() === document.timestamp + tx => tx.timestamp.getTime() === document.timestamp )?.outputAddress ?? null, hash: txHashes.find( diff --git a/packages/api/src/server.js b/packages/api/src/server.js index 87c899a38..dd949976a 100644 --- a/packages/api/src/server.js +++ b/packages/api/src/server.js @@ -13,29 +13,29 @@ const DocumentsController = require('./controllers/DocumentsController') const IdentitiesController = require('./controllers/IdentitiesController') const DataContractsController = require('./controllers/DataContractsController') const ValidatorsController = require('./controllers/ValidatorsController') -const {getKnex} = require('./utils') +const { getKnex } = require('./utils') const BlocksDAO = require('./dao/BlocksDAO') const DAPI = require('./DAPI') const RateController = require('./controllers/RateController') const DAPIClient = require('@dashevo/dapi-client') -const {default: loadWasmDpp} = require('dash').PlatformProtocol +const { default: loadWasmDpp } = require('dash').PlatformProtocol -function errorHandler(err, req, reply) { +function errorHandler (err, req, reply) { if (err instanceof ServiceNotAvailableError) { - return reply.status(503).send({error: 'tenderdash/dashcore backend is not available'}) + return reply.status(503).send({ error: 'tenderdash/dashcore backend is not available' }) } if (err?.constructor?.name === 'InvalidStateTransitionError') { const [error] = err.getErrors() - const {code, message} = error + const { code, message } = error - return reply.status(500).send({error: message, code}) + return reply.status(500).send({ error: message, code }) } console.error(err) reply.status(500) - reply.send({error: err.message}) + reply.send({ error: err.message }) } let client @@ -56,7 +56,7 @@ module.exports = { network: process.env.NETWORK ?? 'testnet' }) - const {dpp} = client.platform + const { dpp } = client.platform dapi = new DAPI(dapiClient, dpp) @@ -105,9 +105,9 @@ module.exports = { new fastify.metrics.client.Gauge({ name: 'platform_explorer_api_block_height', help: 'The latest block height in the API', - async collect() { + async collect () { const blockDAO = new BlocksDAO(knex) - const {resultSet: [block]} = await blockDAO.getBlocks(1, 1, 'desc') + const { resultSet: [block] } = await blockDAO.getBlocks(1, 1, 'desc') this.set(block.header.height) } diff --git a/packages/api/src/utils.js b/packages/api/src/utils.js index 40806aead..d8e98a588 100644 --- a/packages/api/src/utils.js +++ b/packages/api/src/utils.js @@ -3,12 +3,12 @@ const StateTransitionEnum = require('./enums/StateTransitionEnum') const PoolingEnum = require('./enums/PoolingEnum') const DocumentActionEnum = require('./enums/DocumentActionEnum') const net = require('net') -const {TCP_CONNECT_TIMEOUT, DPNS_CONTRACT, NETWORK} = require('./constants') -const {base58} = require('@scure/base') +const { TCP_CONNECT_TIMEOUT, DPNS_CONTRACT, NETWORK } = require('./constants') +const { base58 } = require('@scure/base') const convertToHomographSafeChars = require('dash/build/utils/convertToHomographSafeChars').default const Intervals = require('./enums/IntervalsEnum') const dashcorelib = require('@dashevo/dashcore-lib') -const {InstantAssetLockProof, ChainAssetLockProof} = require('@dashevo/wasm-dpp') +const { InstantAssetLockProof, ChainAssetLockProof } = require('@dashevo/wasm-dpp') const SecurityLevelEnum = require('./enums/SecurityLevelEnum') const KeyPurposeEnum = require('./enums/KeyPurposeEnum') const KeyTypeEnum = require('./enums/KeyTypeEnum') @@ -22,7 +22,7 @@ const getKnex = () => { user: process.env.POSTGRES_USER, database: process.env.POSTGRES_DB, password: process.env.POSTGRES_PASS, - ssl: process.env.POSTGRES_SSL ? {rejectUnauthorized: false} : false + ssl: process.env.POSTGRES_SSL ? { rejectUnauthorized: false } : false } }) } @@ -437,10 +437,10 @@ const getAliasInfo = async (alias, dapi) => { ] ) - return {alias, contestedState} + return { alias, contestedState } } - return {alias, contestedState: null} + return { alias, contestedState: null } } module.exports = { diff --git a/packages/api/test/integration/identities.spec.js b/packages/api/test/integration/identities.spec.js index c10718f0e..1b1a42b4e 100644 --- a/packages/api/test/integration/identities.spec.js +++ b/packages/api/test/integration/identities.spec.js @@ -282,7 +282,7 @@ describe('Identities routes', () => { status: withdrawal.status, timestamp: withdrawal.timestamp, amount: withdrawal.amount, - withdrawalAddress: null, + withdrawalAddress: null }))) }) From 87a9d1573f7e8e1ca1330a0e8ceecedd7bff01df Mon Sep 17 00:00:00 2001 From: owl352 Date: Thu, 28 Nov 2024 00:08:50 +0300 Subject: [PATCH 3/5] readme fix --- packages/api/README.md | 1 + packages/api/src/controllers/IdentitiesController.js | 1 - packages/frontend/src/app/api/content.md | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/api/README.md b/packages/api/README.md index bc661792c..5e956b8ff 100644 --- a/packages/api/README.md +++ b/packages/api/README.md @@ -738,6 +738,7 @@ GET /identity/A1rgGVjRGuznRThdAA316VEEpKuVQ7mV8mBK1BFJvXnb/withdrawals?limit=5 "sender": "A1rgGVjRGuznRThdAA316VEEpKuVQ7mV8mBK1BFJvXnb", "status": "COMPLETE", "amount": 200000, + "timestamp": 1729096625509, "withdrawalAddress": "yeRZBWYfeNE4yVUHV4ZLs83Ppn9aMRH57A", "hash": "113F86F4D1F48159B0D6690F3C5F8F33E39243086C041CF016454A66AD63F025" }, diff --git a/packages/api/src/controllers/IdentitiesController.js b/packages/api/src/controllers/IdentitiesController.js index 14c837523..9d811f8b6 100644 --- a/packages/api/src/controllers/IdentitiesController.js +++ b/packages/api/src/controllers/IdentitiesController.js @@ -104,7 +104,6 @@ class IdentitiesController { status: document.status ?? null, timestamp: document.timestamp ?? null, amount: document.amount ?? null, - withdrawalAddress: decodedTx.find( tx => tx.timestamp.getTime() === document.timestamp diff --git a/packages/frontend/src/app/api/content.md b/packages/frontend/src/app/api/content.md index 754d6fbdf..c07329965 100644 --- a/packages/frontend/src/app/api/content.md +++ b/packages/frontend/src/app/api/content.md @@ -705,6 +705,7 @@ GET /identity/A1rgGVjRGuznRThdAA316VEEpKuVQ7mV8mBK1BFJvXnb/withdrawals?limit=5 "sender": "A1rgGVjRGuznRThdAA316VEEpKuVQ7mV8mBK1BFJvXnb", "status": "COMPLETE", "amount": 200000, + "timestamp": 1729096625509, "withdrawalAddress": "yeRZBWYfeNE4yVUHV4ZLs83Ppn9aMRH57A", "hash": "113F86F4D1F48159B0D6690F3C5F8F33E39243086C041CF016454A66AD63F025" }, From 29f70ea9db8bbdd7fb878c91828ca77ea51a82b7 Mon Sep 17 00:00:00 2001 From: owl352 Date: Thu, 28 Nov 2024 00:11:56 +0300 Subject: [PATCH 4/5] empty array fix --- packages/api/src/controllers/IdentitiesController.js | 2 +- packages/api/test/integration/identities.spec.js | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/api/src/controllers/IdentitiesController.js b/packages/api/src/controllers/IdentitiesController.js index 9d811f8b6..97b2202cd 100644 --- a/packages/api/src/controllers/IdentitiesController.js +++ b/packages/api/src/controllers/IdentitiesController.js @@ -86,7 +86,7 @@ class IdentitiesController { const documents = await this.dapi.getDocuments(WITHDRAWAL_CONTRACT_TYPE, WithdrawalsContract, identifier, limit) if (documents.length === 0) { - return response.status(404).send({ message: 'not found' }) + return response.send(new PaginatedResultSet([], null, null, null)) } const timestamps = documents.map(document => new Date(document.timestamp).toISOString()) diff --git a/packages/api/test/integration/identities.spec.js b/packages/api/test/integration/identities.spec.js index 1b1a42b4e..a452b86b9 100644 --- a/packages/api/test/integration/identities.spec.js +++ b/packages/api/test/integration/identities.spec.js @@ -288,9 +288,10 @@ describe('Identities routes', () => { it('should return 404 whe identity not exist', async () => { mock.method(DAPI.prototype, 'getDocuments', async () => []) - await client.get('/identity/1234123123PFdomuTVvNy3VRrvWgvkKPzqehEBpNf2nk6/withdrawals') - .expect(404) + const { body } = await client.get('/identity/1234123123PFdomuTVvNy3VRrvWgvkKPzqehEBpNf2nk6/withdrawals') .expect('Content-Type', 'application/json; charset=utf-8') + + assert.deepEqual(body.resultSet, []) }) }) From c95950673e32ccf31cbb47b365b366c632984268 Mon Sep 17 00:00:00 2001 From: owl352 Date: Thu, 28 Nov 2024 00:17:24 +0300 Subject: [PATCH 5/5] names fix --- packages/api/src/controllers/IdentitiesController.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/api/src/controllers/IdentitiesController.js b/packages/api/src/controllers/IdentitiesController.js index 97b2202cd..e9529c847 100644 --- a/packages/api/src/controllers/IdentitiesController.js +++ b/packages/api/src/controllers/IdentitiesController.js @@ -91,11 +91,11 @@ class IdentitiesController { const timestamps = documents.map(document => new Date(document.timestamp).toISOString()) - const txHashes = await this.identitiesDAO.getIdentityWithdrawalsByTimestamps(identifier, timestamps) + const withdrawals = await this.identitiesDAO.getIdentityWithdrawalsByTimestamps(identifier, timestamps) - const decodedTx = await Promise.all(txHashes.map(async tx => ({ - ...await decodeStateTransition(this.client, tx.data), - timestamp: tx.timestamp + const decodedTx = await Promise.all(withdrawals.map(async withdrawal => ({ + ...await decodeStateTransition(this.client, withdrawal.data), + timestamp: withdrawal.timestamp }))) const resultSet = documents.map(document => ({ @@ -109,7 +109,7 @@ class IdentitiesController { tx => tx.timestamp.getTime() === document.timestamp )?.outputAddress ?? null, - hash: txHashes.find( + hash: withdrawals.find( hash => new Date(hash.timestamp).toISOString() === new Date(document.timestamp).toISOString())?.hash ?? null }))