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) => { @@ -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),

1
package.json

@ -21,6 +21,7 @@ @@ -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",

10
routes/block.js

@ -5,7 +5,7 @@ var router = express.Router(); @@ -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) { @@ -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) { @@ -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,
});

10
routes/transaction.js

@ -11,7 +11,7 @@ router.get('/:txid', async function(req, res, next) { @@ -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) { @@ -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,
});
});

2
views/block.jade

@ -4,7 +4,7 @@ block content @@ -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}

3
views/transaction.jade

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

Loading…
Cancel
Save