diff --git a/api/bfacontroller.js b/api/bfacontroller.js index 96cd02712cd94f1aef100bd7a00f4953585c2656..5553c55c7ac2d29bc148c3a90a8ec415bb9f0e8f 100644 --- a/api/bfacontroller.js +++ b/api/bfacontroller.js @@ -161,9 +161,75 @@ verify : async function (req, res){ }); } - } -} + }, + balance : async function (req, res){ + const now = new Date(); + try{ + const account = req.query.account || config.account.address; + console.log("[" + utils.dateFormat(now, "%d/%m/%Y %H:%M:%S", false) + "] : balance : ("+account+")"); + + var bal = await web3.eth.getBalance(account); + var eth = web3.utils.fromWei(bal, "ether") + " ETH"; + + return res.json({ + account: account, + balanceETH: eth, + balanceWEI: bal + }); + } + catch(err){ + + console.log("[" + utils.dateFormat(now, "%d/%m/%Y %H:%M:%S", false) + "] : ERROR balance : ", err); + + return res.status(500).json({ + messages: "No se pudo realizar la operacion", + status: "failure" + }); + + } + }, + block : async function (req, res){ + const now = new Date(); + try{ + const block_number = req.query.number; + console.log("[" + utils.dateFormat(now, "%d/%m/%Y %H:%M:%S", false) + "] : block : ("+block_number+")"); + + const block = await web3.eth.getBlock(block_number); + + return res.json(block); + } + catch(err){ + console.log("[" + utils.dateFormat(now, "%d/%m/%Y %H:%M:%S", false) + "] : ERROR block : ", err); + return res.status(500).json({ + messages: "No se pudo realizar la operacion", + status: "failure" + }); + + } + } , + tx : async function (req, res){ + const now = new Date(); + try{ + const tx_hash = req.query.hash; + console.log("[" + utils.dateFormat(now, "%d/%m/%Y %H:%M:%S", false) + "] : tx : ("+tx_hash+")"); + + var tx = await web3.eth.getTransaction(tx_hash); + + return res.json(tx); + } + catch(err){ + + console.log("[" + utils.dateFormat(now, "%d/%m/%Y %H:%M:%S", false) + "] : ERROR tx : ", err); + + return res.status(500).json({ + messages: "No se pudo realizar la operacion", + status: "failure" + }); + + } + } +} \ No newline at end of file diff --git a/api/routes.js b/api/routes.js index 9c507c52c10f92924d23039e49456d1fc25720c0..934f2314221e8b49364dfbe8e89c5fa48d321087 100644 --- a/api/routes.js +++ b/api/routes.js @@ -12,6 +12,18 @@ router.get('/address', (req, res) => { res.send(config.account.address); }) +router.get('/balance', async (req, res) => { + await BfaController.balance(req, res); +}) + +router.get('/block', async (req, res) => { + await BfaController.block(req, res); +}) + +router.get('/tx', async (req, res) => { + await BfaController.tx(req, res); +}) + router.post('/stamp', async (req, res) => { await BfaController.stamp(req, res); })