From 95294265a1212534ee105d7f3b47a70ade1e0a61 Mon Sep 17 00:00:00 2001 From: MHaris-Ferrum Date: Thu, 29 Aug 2024 20:05:19 +0500 Subject: [PATCH] txtype and smartContract api integrated --- src/controllers/contract.controller.ts | 16 ++++++++++++++++ src/models/quantumPortalTransaction.model.ts | 1 + src/routes/contract.route.ts | 2 ++ src/services/contract.service.ts | 8 ++++++++ src/services/node.service.ts | 1 + 5 files changed, 28 insertions(+) diff --git a/src/controllers/contract.controller.ts b/src/controllers/contract.controller.ts index a1e2e8d..27076ea 100644 --- a/src/controllers/contract.controller.ts +++ b/src/controllers/contract.controller.ts @@ -17,3 +17,19 @@ export const registerContract = async ( next(error); } }; + +export const getContract = async ( + req: Request, + res: Response, + next: NextFunction, +): Promise => { + try { + console.log(req.params); + const contract = await contractService.getSmartContract( + req.params.contractAddress, + ); + res.send(contract); + } catch (error) { + next(error); + } +}; diff --git a/src/models/quantumPortalTransaction.model.ts b/src/models/quantumPortalTransaction.model.ts index c3aeb8f..a0b93a1 100644 --- a/src/models/quantumPortalTransaction.model.ts +++ b/src/models/quantumPortalTransaction.model.ts @@ -3,6 +3,7 @@ import mongoose, { Schema } from 'mongoose'; const quantumPortalTransactionSchema = new Schema({ hash: String, type: Number, + txType: [String], block: Number, nonce: Number, status: String, diff --git a/src/routes/contract.route.ts b/src/routes/contract.route.ts index 03b08fa..082e0d0 100644 --- a/src/routes/contract.route.ts +++ b/src/routes/contract.route.ts @@ -10,4 +10,6 @@ router.post( contractController.registerContract, ); +router.get('/:contractAddress', contractController.getContract); + export default router; diff --git a/src/services/contract.service.ts b/src/services/contract.service.ts index 755dc2b..ebe3da6 100644 --- a/src/services/contract.service.ts +++ b/src/services/contract.service.ts @@ -74,6 +74,14 @@ export const registerContract = async ( return newAccount; }; +export const getSmartContract = async (contractAddress: string) => { + const contract = await axios.get( + `${config.explorerUrl}/api/v2/smart-contracts/${contractAddress}`, + ); + console.log('contract', contract); + return contract?.data; +}; + export function sha256sync(hexData: string): string { const dataWa = encHex.parse(hexData); const hash: WordArray = SHA256(dataWa); diff --git a/src/services/node.service.ts b/src/services/node.service.ts index 576c940..0811dc1 100644 --- a/src/services/node.service.ts +++ b/src/services/node.service.ts @@ -49,6 +49,7 @@ export const processBlockAndTransaction = async ( const saved = await transactionsService.saveTransaction({ hash: tx.hash, type: tx.type, + txType: tx.tx_types, blockNumber: tx.block, status: tx.status, method: tx.method,