-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtransaction.js
56 lines (48 loc) · 1.32 KB
/
transaction.js
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var models = require('../models');
var express = require('express');
var router = express.Router();
/* GET home page. */
router.get('/:txid', async function(req, res, next) {
const txid = encodeURI(req.params.txid);
const transaction = await models.Transaction.findOne({
where: {
txid,
},
include: [{
attributes: ['hash', 'time', 'height'],
model: models.Block,
},{
model: models.Vout,
include: [
{
model: models.Address,
}, {
model: models.Transaction,
}
],
},],
});
if (transaction === null) {
res.status(404).render('404');
return;
}
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;
const txJson = transaction.toJSON();
const txTemplate = Object.assign(txJson, {
vins: txJson.Vouts.filter((vout) => vout.TransactionVouts.direction === 0),
vouts: txJson.Vouts.filter((vout) => vout.TransactionVouts.direction === 1),
});
txTemplate.blockTime = transaction.Block.time.toUTCString();
res.render('transaction', {
transaction: txTemplate,
// vouts,
confirmations,
});
});
module.exports = router;