Browse Source

Remove confirmation for db, add confimations to transaction page

stuff
xcps 7 years ago
parent
commit
a186ca9ebf
  1. 1
      models/block.js
  2. 1
      package.json
  3. 10
      routes/block.js
  4. 10
      routes/transaction.js
  5. 2
      views/block.jade
  6. 3
      views/transaction.jade

1
models/block.js

@ -6,7 +6,6 @@ module.exports = (sequelize, DataTypes) => {
primaryKey: true, primaryKey: true,
}, },
hash: DataTypes.STRING(64), hash: DataTypes.STRING(64),
confirmations: DataTypes.MEDIUMINT.UNSIGNED,
size: DataTypes.MEDIUMINT.UNSIGNED, size: DataTypes.MEDIUMINT.UNSIGNED,
version: DataTypes.TINYINT.UNSIGNED, version: DataTypes.TINYINT.UNSIGNED,
merkleroot: DataTypes.STRING(64), merkleroot: DataTypes.STRING(64),

1
package.json

@ -21,6 +21,7 @@
"cookie-parser": "~1.4.3", "cookie-parser": "~1.4.3",
"debug": "~2.6.9", "debug": "~2.6.9",
"express": "~4.15.5", "express": "~4.15.5",
"forever": "^0.15.3",
"jade": "~1.11.0", "jade": "~1.11.0",
"morgan": "~1.9.0", "morgan": "~1.9.0",
"mysql": "^2.15.0", "mysql": "^2.15.0",

10
routes/block.js

@ -5,7 +5,7 @@ var router = express.Router();
/* GET home page. */ /* GET home page. */
router.get('/:hash', async function(req, res, next) { router.get('/:hash', async function(req, res, next) {
const hash = encodeURI(req.params.hash); const hash = encodeURI(req.params.hash);
const block = await models.Block.findOne({ const blockInstance = await models.Block.findOne({
where: { where: {
hash, hash,
}, },
@ -13,7 +13,7 @@ router.get('/:hash', async function(req, res, next) {
model: models.Transaction, model: models.Transaction,
}, },
}); });
if (block === null) { if (blockInstance === null) {
res.status(404).render('404'); res.status(404).render('404');
return; return;
} }
@ -21,9 +21,11 @@ router.get('/:hash', async function(req, res, next) {
attributes: [ attributes: [
[models.sequelize.fn('MAX', models.sequelize.col('height')), 'maxheight'] [models.sequelize.fn('MAX', models.sequelize.col('height')), 'maxheight']
], ],
raw: true,
}); });
block.dataValues.confirmations = lastBlock.dataValues.maxheight - block.height + 1; const block = blockInstance.toJSON();
block.dataValues.time = block.time.toUTCString(); block.confirmations = lastBlock.maxheight - block.height + 1;
block.time = block.time.toUTCString();
res.render('block', { res.render('block', {
block, block,
}); });

10
routes/transaction.js

@ -11,7 +11,7 @@ router.get('/:txid', async function(req, res, next) {
txid, txid,
}, },
include: [{ include: [{
attributes: ['hash', 'time'], attributes: ['hash', 'time', 'height'],
model: models.Block, model: models.Block,
},{ },{
model: models.Vout, 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(); transaction.blockTime = transaction.Block.time.toUTCString();
res.render('transaction', { res.render('transaction', {
transaction, transaction,
vouts, vouts,
confirmations,
}); });
}); });

2
views/block.jade

@ -4,7 +4,7 @@ block content
h3 Block h3 Block
table table
each key in Object.keys(block.dataValues) each key in Object.keys(block)
if (key === 'nextblockhash') if (key === 'nextblockhash')
tr tr
td.capitalize #{key} td.capitalize #{key}

3
views/transaction.jade

@ -14,6 +14,9 @@ block content
tr tr
td Block time td Block time
td #{transaction.blockTime} td #{transaction.blockTime}
tr
td Confirmations
td #{confirmations}
h3 In h3 In
if transaction.txtx.length if transaction.txtx.length

Loading…
Cancel
Save