From ea3f5eb6e6cfdc631c532ee601ffb4d7e3f25e54 Mon Sep 17 00:00:00 2001 From: Hernan Hegykozi <hhegykozi@srt.gob.ar> Date: Wed, 6 Apr 2022 15:05:36 -0300 Subject: [PATCH] Se agregan endpoint de balance, block y tx --- api/bfacontroller.js | 70 ++++++++++++++++++++++++++++++++++++++++++-- api/routes.js | 12 ++++++++ 2 files changed, 80 insertions(+), 2 deletions(-) diff --git a/api/bfacontroller.js b/api/bfacontroller.js index 96cd027..5553c55 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 9c507c5..934f231 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); }) -- GitLab