Skip to content

Commit 143c37c

Browse files
Only accept stake address of hex length 58
1 parent 231bc79 commit 143c37c

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

src/controllers/stakeAddress.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1-
import { Request, Response, Router } from "express";
2-
import { handlerWrapper } from "../errors/AppError";
3-
import { convertToHexIfBech32, validateAddress } from "../helpers/validator";
4-
import { fetchStakeAddressDetails } from "../repository/stakeAddress";
1+
import { Request, Response, Router } from 'express'
2+
import { handlerWrapper } from '../errors/AppError'
3+
import { convertToHexIfBech32, validateAddress } from '../helpers/validator'
4+
import { fetchStakeAddressDetails } from '../repository/stakeAddress'
55

6-
const router = Router();
6+
const router = Router()
77

88
const getStakeAddressDetails = async (req: Request, res: Response): Promise<any> => {
9-
let address = convertToHexIfBech32(req.query.address as string)
10-
if (validateAddress(address)){
11-
address = address.length === 56 ? `e0${address}`:address
12-
}else{
13-
return res.status(400).json({message:'Provide a valid address'})
14-
}
9+
let address = convertToHexIfBech32(req.query.address as string)
10+
if (validateAddress(address)) {
11+
if (address.length == 56) {
12+
return res.status(400).json({ mesage: `Provide a valid address` })
13+
}
14+
} else {
15+
return res.status(400).json({ message: 'Provide a valid address' })
16+
}
1517

16-
const result = await fetchStakeAddressDetails(address)
17-
return res.status(200).json(result);
18-
};
18+
const result = await fetchStakeAddressDetails(address)
19+
return res.status(200).json(result)
20+
}
1921

20-
router.get('/', handlerWrapper(getStakeAddressDetails));
22+
router.get('/', handlerWrapper(getStakeAddressDetails))
2123

22-
export default router;
24+
export default router

0 commit comments

Comments
 (0)