Skip to content

Commit

Permalink
Merge pull request #38 from MHaris-Ferrum/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
AbdulAhadArain authored Aug 30, 2024
2 parents cd46c57 + f1272d4 commit 5871522
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 2 deletions.
26 changes: 26 additions & 0 deletions src/controllers/accounts.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> => {
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<void> => {
try {
const address = await accountService.getAddressLogs(req.params.address);
res.send(address);
} catch (error) {
next(error);
}
};
18 changes: 18 additions & 0 deletions src/controllers/transactions.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@ export const getTransactions = async (
next(error);
}
};

export const getInternalTransactions = async (
req: Request,
res: Response,
next: NextFunction,
): Promise<void> => {
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,
Expand Down
3 changes: 3 additions & 0 deletions src/routes/accounts.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ router.get(
accountController.getBalances,
);

router.get('/addresses/:address', accountController.getAddressDetail);
router.get('/addresses/:address/logs', accountController.getAddressLogs);

export default router;
5 changes: 5 additions & 0 deletions src/routes/transactions.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
16 changes: 16 additions & 0 deletions src/services/account.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -62,3 +64,17 @@ export const getAccount = async (address: string): Promise<any> => {
}
return account;
};

export const getAddressDetail = async (address: string): Promise<any> => {
const addressDetail = await axios.get(
`${config.explorerUrl}/api/v2/addresses/${address}`,
);
return addressDetail.data;
};

export const getAddressLogs = async (address: string): Promise<any> => {
const addressLogs = await axios.get(
`${config.explorerUrl}/api/v2/addresses/${address}/logs`,
);
return addressLogs.data;
};
33 changes: 31 additions & 2 deletions src/services/transaction.service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -105,7 +104,37 @@ export const getTxs = async (
};
return result;
};

export const getInternalTxs = async (
address: string,
page: number,
limit: number,
): Promise<any> => {
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,
Expand Down
8 changes: 8 additions & 0 deletions src/validations/transaction.validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(''),
Expand Down

0 comments on commit 5871522

Please sign in to comment.