1
0
mirror of https://github.com/GOSTSec/gostexplr synced 2025-01-15 01:00:16 +00:00
gostexplr/routes/block.js

36 lines
840 B
JavaScript
Raw Normal View History

2018-02-03 21:14:56 +05:00
var models = require('../models');
var express = require('express');
var router = express.Router();
/* GET home page. */
2018-02-03 23:54:25 +05:00
router.get('/:hash', async function(req, res, next) {
2018-02-03 21:14:56 +05:00
const hash = encodeURI(req.params.hash);
const blockInstance = await models.Block.findOne({
2018-02-03 21:14:56 +05:00
where: {
hash,
},
include: {
model: models.Transaction,
},
2018-02-04 23:00:35 +05:00
});
if (blockInstance === null) {
2018-02-03 23:54:25 +05:00
res.status(404).render('404');
return;
}
2018-02-04 23:00:35 +05:00
const lastBlock = await models.Block.findOne({
attributes: [
[models.sequelize.fn('MAX', models.sequelize.col('height')), 'maxheight']
],
raw: true,
2018-02-04 23:00:35 +05:00
});
const block = blockInstance.toJSON();
block.confirmations = lastBlock.maxheight - block.height + 1;
block.time = block.time.toUTCString();
2018-02-03 23:54:25 +05:00
res.render('block', {
block,
2018-02-03 21:14:56 +05:00
});
2018-02-03 23:54:25 +05:00
2018-02-03 21:14:56 +05:00
});
module.exports = router;