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

55 lines
1.2 KiB
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('/:txid', async function(req, res, next) {
2018-02-03 21:14:56 +05:00
const txid = encodeURI(req.params.txid);
2018-02-03 23:54:25 +05:00
const transaction = await models.Transaction.findOne({
2018-02-03 21:14:56 +05:00
where: {
txid,
},
include: [{
attributes: ['hash', 'time', 'height'],
2018-02-03 21:14:56 +05:00
model: models.Block,
},{
model: models.Vout,
include: {
model: models.Address,
}
}, {
model: models.Transaction,
as: 'txtx',
}],
2018-02-03 23:54:25 +05:00
});
if (transaction === null) {
res.status(404).render('404');
return;
}
const vouts = [];
transaction.Vouts.forEach((vout) => {
vout.Addresses.forEach((address) => {
vouts.push({
address: address.address,
value: vout.value,
2018-02-03 21:14:56 +05:00
});
});
});
const lastBlock = await models.Block.findOne({
attributes: [
[models.sequelize.fn('MAX', models.sequelize.col('height')), 'maxheight']
],
raw: true,
});
const confirmations = lastBlock.maxheight - transaction.Block.height + 1;
2018-02-04 22:47:36 +05:00
transaction.blockTime = transaction.Block.time.toUTCString();
2018-02-03 23:54:25 +05:00
res.render('transaction', {
transaction,
vouts,
confirmations,
2018-02-03 23:54:25 +05:00
});
2018-02-03 21:14:56 +05:00
});
module.exports = router;