Skip to content

Commit b0c7e9c

Browse files
Merge pull request #6 from cardanoapi/fix/stake-address-registration
Fix/stake address registration
2 parents f44a1ac + fb3231d commit b0c7e9c

File tree

4 files changed

+46
-52
lines changed

4 files changed

+46
-52
lines changed

src/controllers/address.ts

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

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

88
const getFaucetBalance = 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+
const balance = await fetchFaucetBalance(address)
12+
return res.status(200).json(balance)
13+
} else {
14+
return res.status(400).json({ message: 'Provide a valid address' })
15+
}
16+
}
1517

16-
const balance = await fetchFaucetBalance(address)
18+
router.get('/balance', handlerWrapper(getFaucetBalance))
1719

18-
return res.status(200).json(balance);
19-
};
20-
21-
router.get('/balance', handlerWrapper(getFaucetBalance));
22-
23-
export default router;
20+
export default router

src/controllers/delegation.ts

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

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

88
const getDelegation = 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-
}
15-
const result = await fetchDelegationDetail(address)
16-
return res.status(200).json(result);
17-
};
9+
let address = convertToHexIfBech32(req.query.address as string)
10+
if (validateAddress(address)) {
11+
const result = await fetchDelegationDetail(address)
12+
return res.status(200).json(result)
13+
} else {
14+
return res.status(400).json({ message: 'Provide a valid address' })
15+
}
16+
}
1817

19-
router.get('/', handlerWrapper(getDelegation));
18+
router.get('/', handlerWrapper(getDelegation))
2019

21-
export default router;
20+
export default router

src/controllers/stakeAddress.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
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+
const result = await fetchStakeAddressDetails(address)
12+
return res.status(200).json(result)
13+
} else {
14+
return res.status(400).json({ message: 'Provide a valid address' })
15+
}
16+
}
1517

16-
const result = await fetchStakeAddressDetails(address)
17-
return res.status(200).json(result);
18-
};
18+
router.get('/', handlerWrapper(getStakeAddressDetails))
1919

20-
router.get('/', handlerWrapper(getStakeAddressDetails));
21-
22-
export default router;
20+
export default router

src/helpers/validator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export function fromHex(prefix: string, hex: string) {
105105

106106
export function validateAddress(value: string): boolean {
107107
if (isHexValue(value)) {
108-
return value.length === 56 || value.length === 58
108+
return value.length === 58
109109
}
110110
return false
111111
}

0 commit comments

Comments
 (0)