forked from ferrumnet/quantum-portal-explorer-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
explorer module added and search api created
- Loading branch information
1 parent
f5dadd1
commit 8ca6ea7
Showing
9 changed files
with
70 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import Web3 from 'web3'; | ||
import { transactionsService, accountService, blockService } from '../services'; | ||
import { Request, Response, NextFunction } from 'express'; | ||
import { isTransactionOrBlockHash } from '../utils/constants'; | ||
import ApiError from '../utils/ApiError'; | ||
import httpStatus from 'http-status'; | ||
|
||
export const searchData = async ( | ||
req: Request, | ||
res: Response, | ||
next: NextFunction, | ||
): Promise<void> => { | ||
try { | ||
if ( | ||
Web3.utils.isHex(req.query.data as string) && | ||
isTransactionOrBlockHash(req.query.data as string) | ||
) { | ||
let hash; | ||
hash = await transactionsService.getTransaction(req.query.data as string); | ||
if (!hash) { | ||
hash = await blockService.getBlockByBlockHash(req.query.data as string); | ||
} | ||
if (!hash) { | ||
next(new ApiError(httpStatus.BAD_REQUEST, 'Not Found')); | ||
} | ||
res.send(hash); | ||
} else if (Web3.utils.isAddress(req.query.data as string)) { | ||
const account = await accountService.getAccount(req.query.data as string); | ||
res.send(account); | ||
} else { | ||
next(new ApiError(httpStatus.BAD_REQUEST, 'Not Found')); | ||
} | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import express from 'express'; | ||
const router = express.Router(); | ||
import validate from '../middlewares/validate.middleware'; | ||
import { explorerController } from '../controllers'; | ||
import { explorerValidation } from '../validations'; | ||
|
||
router.get( | ||
'/search', | ||
validate(explorerValidation.searchData), | ||
explorerController.searchData, | ||
); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import Joi from 'joi'; | ||
|
||
export const searchData = { | ||
query: Joi.object().keys({ | ||
data: Joi.string().required(), | ||
}), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters