diff --git a/models/block.js b/models/block.js index 9b9e978..d1b5b0d 100644 --- a/models/block.js +++ b/models/block.js @@ -6,7 +6,6 @@ module.exports = (sequelize, DataTypes) => { primaryKey: true, }, hash: DataTypes.STRING(64), - confirmations: DataTypes.MEDIUMINT.UNSIGNED, size: DataTypes.MEDIUMINT.UNSIGNED, version: DataTypes.TINYINT.UNSIGNED, merkleroot: DataTypes.STRING(64), diff --git a/package.json b/package.json index 8e35783..b69af41 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "cookie-parser": "~1.4.3", "debug": "~2.6.9", "express": "~4.15.5", + "forever": "^0.15.3", "jade": "~1.11.0", "morgan": "~1.9.0", "mysql": "^2.15.0", diff --git a/routes/block.js b/routes/block.js index ea1dcc1..9708ae5 100644 --- a/routes/block.js +++ b/routes/block.js @@ -5,7 +5,7 @@ var router = express.Router(); /* GET home page. */ router.get('/:hash', async function(req, res, next) { const hash = encodeURI(req.params.hash); - const block = await models.Block.findOne({ + const blockInstance = await models.Block.findOne({ where: { hash, }, @@ -13,7 +13,7 @@ router.get('/:hash', async function(req, res, next) { model: models.Transaction, }, }); - if (block === null) { + if (blockInstance === null) { res.status(404).render('404'); return; } @@ -21,9 +21,11 @@ router.get('/:hash', async function(req, res, next) { attributes: [ [models.sequelize.fn('MAX', models.sequelize.col('height')), 'maxheight'] ], + raw: true, }); - block.dataValues.confirmations = lastBlock.dataValues.maxheight - block.height + 1; - block.dataValues.time = block.time.toUTCString(); + const block = blockInstance.toJSON(); + block.confirmations = lastBlock.maxheight - block.height + 1; + block.time = block.time.toUTCString(); res.render('block', { block, }); diff --git a/routes/transaction.js b/routes/transaction.js index 9b02549..813d8b6 100644 --- a/routes/transaction.js +++ b/routes/transaction.js @@ -11,7 +11,7 @@ router.get('/:txid', async function(req, res, next) { txid, }, include: [{ - attributes: ['hash', 'time'], + attributes: ['hash', 'time', 'height'], model: models.Block, },{ model: models.Vout, @@ -36,10 +36,18 @@ router.get('/:txid', async function(req, res, next) { }); }); }); + 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; transaction.blockTime = transaction.Block.time.toUTCString(); res.render('transaction', { transaction, vouts, + confirmations, }); }); diff --git a/views/block.jade b/views/block.jade index d402ef1..d01c003 100644 --- a/views/block.jade +++ b/views/block.jade @@ -4,7 +4,7 @@ block content h3 Block table - each key in Object.keys(block.dataValues) + each key in Object.keys(block) if (key === 'nextblockhash') tr td.capitalize #{key} diff --git a/views/transaction.jade b/views/transaction.jade index ea56feb..d45bb78 100644 --- a/views/transaction.jade +++ b/views/transaction.jade @@ -14,6 +14,9 @@ block content tr td Block time td #{transaction.blockTime} + tr + td Confirmations + td #{confirmations} h3 In if transaction.txtx.length