-
Notifications
You must be signed in to change notification settings - Fork 1
/
apis.ts
31 lines (29 loc) · 970 Bytes
/
apis.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { Router, json } from 'express'
import { doTransaction, findAllAccountBalance, searchTxnHashMerkleTree } from './blockchain'
const router = Router()
router.use(json())
router.post('/transaction', async (req, res) => {
try {
const transactionDetails = await doTransaction(req.body.debitAccount, req.body.creditAccount, req.body.amount)
res.send(transactionDetails)
} catch (error: any) {
console.log(error)
res.status(400).send({ error: error.message })
}
})
router.post('/verify', async (req, res) => {
try {
const transactionDetails = await searchTxnHashMerkleTree(req.body.txnHash)
res.send(transactionDetails)
} catch (error: any) {
console.log(error)
res.status(400).send({ error: error.message })
}
})
router.get('/balance', async (req, res) => {
res.send(await findAllAccountBalance())
})
router.use((err: any, req: any, res: any, next: any) => {
res.status(500).send({ error: err })
})
export default router