diff --git a/src/controllers/accounts.controller.ts b/src/controllers/accounts.controller.ts index 6e73e05..cd1f0b5 100644 --- a/src/controllers/accounts.controller.ts +++ b/src/controllers/accounts.controller.ts @@ -37,3 +37,29 @@ export const getBalances = async ( // const balances = accountService.accountBalances(req.query.address as string); // res.send(balances); }; + +export const getAddressDetail = async ( + req: Request, + res: Response, + next: NextFunction, +): Promise => { + try { + const address = await accountService.getAddressDetail(req.params.address); + res.send(address); + } catch (error) { + next(error); + } +}; + +export const getAddressLogs = async ( + req: Request, + res: Response, + next: NextFunction, +): Promise => { + try { + const address = await accountService.getAddressLogs(req.params.address); + res.send(address); + } catch (error) { + next(error); + } +}; diff --git a/src/controllers/transactions.controller.ts b/src/controllers/transactions.controller.ts index 6c6cc84..46d955f 100644 --- a/src/controllers/transactions.controller.ts +++ b/src/controllers/transactions.controller.ts @@ -19,6 +19,24 @@ export const getTransactions = async ( next(error); } }; + +export const getInternalTransactions = async ( + req: Request, + res: Response, + next: NextFunction, +): Promise => { + try { + const transactions = await transactionsService.getInternalTxs( + req.query.page as any, + req.query.limit as any, + req.query.address as any, + ); + res.send(transactions); + } catch (error) { + next(error); + } +}; + export const getTransferTokenTransactions = async ( req: Request, res: Response, diff --git a/src/routes/accounts.route.ts b/src/routes/accounts.route.ts index 9e970d8..d72b42d 100644 --- a/src/routes/accounts.route.ts +++ b/src/routes/accounts.route.ts @@ -20,4 +20,7 @@ router.get( accountController.getBalances, ); +router.get('/addresses/:address', accountController.getAddressDetail); +router.get('/addresses/:address/logs', accountController.getAddressLogs); + export default router; diff --git a/src/routes/transactions.route.ts b/src/routes/transactions.route.ts index 8dd52a3..0801669 100644 --- a/src/routes/transactions.route.ts +++ b/src/routes/transactions.route.ts @@ -14,6 +14,11 @@ router.get( validate(transactionValidation.getTransferTokenTransactions), transactionController.getTransferTokenTransactions, ); +router.get( + '/internal-txs/:address', + validate(transactionValidation.getInternalTransactions), + transactionController.getInternalTransactions, +); router.get( '/:txId', validate(transactionValidation.getTransaction), diff --git a/src/services/account.service.ts b/src/services/account.service.ts index dd83d06..47c7c68 100644 --- a/src/services/account.service.ts +++ b/src/services/account.service.ts @@ -4,6 +4,8 @@ import { QuantumPortalContractObjectModel, } from '../models'; import { ITransactionListResponse, QuantumPortalAccount } from '../interfaces'; +import axios from 'axios'; +import config from '../config/config'; // import ApiError from '../utils/ApiError'; // import httpStatus from 'http-status'; @@ -62,3 +64,17 @@ export const getAccount = async (address: string): Promise => { } return account; }; + +export const getAddressDetail = async (address: string): Promise => { + const addressDetail = await axios.get( + `${config.explorerUrl}/api/v2/addresses/${address}`, + ); + return addressDetail.data; +}; + +export const getAddressLogs = async (address: string): Promise => { + const addressLogs = await axios.get( + `${config.explorerUrl}/api/v2/addresses/${address}/logs`, + ); + return addressLogs.data; +}; diff --git a/src/services/transaction.service.ts b/src/services/transaction.service.ts index f64d64d..33ab78c 100644 --- a/src/services/transaction.service.ts +++ b/src/services/transaction.service.ts @@ -1,5 +1,4 @@ import { QuantumPortalTransactionModel } from '../models'; -import { chartData } from '../interfaces/QuantumPortalRemoteTransaction.interface'; import PocContractABI from '../utils/abi/poc.json'; import MGRContractABI from '../utils/abi/ledgerMgr.json'; import { ethers } from 'ethers'; @@ -105,7 +104,37 @@ export const getTxs = async ( }; return result; }; - +export const getInternalTxs = async ( + address: string, + page: number, + limit: number, +): Promise => { + const query: any = { + method: 'finalize', + }; + if (address) { + query.to = address; + } + const docsPromise = QuantumPortalTransactionModel.find(query) + .sort({ timestamp: -1 }) + .skip((page - 1) * limit) + .limit(limit); + const countPromise = + QuantumPortalTransactionModel.countDocuments(query).exec(); + const [totalResults, results] = await Promise.all([ + countPromise, + docsPromise, + ]); + const totalPages = Math.ceil(totalResults / limit); + const result = { + results, + page, + limit, + totalPages, + totalResults, + }; + return result; +}; export const getTransferTokensTxs = async ( type: string, address: string, diff --git a/src/validations/transaction.validation.ts b/src/validations/transaction.validation.ts index cef271d..82e07c4 100644 --- a/src/validations/transaction.validation.ts +++ b/src/validations/transaction.validation.ts @@ -7,6 +7,14 @@ export const getTransactions = { limit: Joi.number().required().default(20), }), }; +export const getInternalTransactions = { + query: Joi.object().keys({ + address: Joi.string(), + page: Joi.number().required().default(1), + limit: Joi.number().required().default(20), + }), +}; + export const getTransferTokenTransactions = { query: Joi.object().keys({ address: Joi.string().allow(''),