Browse Source

Address page

stuff
xcps 7 years ago
parent
commit
2ba2704881
  1. 2
      bin/syncBlockchain.js
  2. 6
      routes/address.js
  3. 17
      routes/transaction.js
  4. 20
      views/transaction.pug

2
bin/syncBlockchain.js

@ -91,7 +91,7 @@ async function saveTransaction(txid, blockHeight) { @@ -91,7 +91,7 @@ async function saveTransaction(txid, blockHeight) {
},
});
if (vout) {
await transaction.addVouts(vout, { through: { direction: 0, }, });
await transaction.addVouts(vout[0], { through: { direction: 0, }, });
} else {
throw('Couldnt find vout for VIN');
}

6
routes/address.js

@ -15,9 +15,7 @@ router.get('/:address/:offset*?', async function(req, res, next) { @@ -15,9 +15,7 @@ router.get('/:address/:offset*?', async function(req, res, next) {
model: models.Vout,
include: {
model: models.Transaction,
include: {
model: models.Vout,
},
},
},
});
@ -26,7 +24,7 @@ router.get('/:address/:offset*?', async function(req, res, next) { @@ -26,7 +24,7 @@ router.get('/:address/:offset*?', async function(req, res, next) {
res.status(404).render('404');
return;
}
const limit = 30;
const paramPage = parseInt(req.params.offset);
const page = isNaN(paramPage) || paramPage < 1 ? 1 : paramPage;

17
routes/transaction.js

@ -20,9 +20,6 @@ router.get('/:txid', async function(req, res, next) { @@ -20,9 +20,6 @@ router.get('/:txid', async function(req, res, next) {
model: models.Address,
}, {
model: models.Transaction,
include: {
model: models.Vout,
},
}
],
},],
@ -33,16 +30,6 @@ router.get('/:txid', async function(req, res, next) { @@ -33,16 +30,6 @@ router.get('/:txid', async function(req, res, next) {
return;
}
// const vouts = [];
// transaction.Vouts.forEach((vout) => {
// vout.Addresses.forEach((address) => {
// vouts.push({
// address: address.address,
// value: vout.value,
// });
// });
// });
const lastBlock = await models.Block.findOne({
attributes: [
[models.sequelize.fn('MAX', models.sequelize.col('height')), 'maxheight']
@ -52,13 +39,13 @@ router.get('/:txid', async function(req, res, next) { @@ -52,13 +39,13 @@ router.get('/:txid', async function(req, res, next) {
const confirmations = lastBlock.maxheight - transaction.Block.height + 1;
const txJson = transaction.toJSON();
// txJson.vins = txJson.Vouts.filter({TransactionVouts: {direction: 0}});
// txJson.vouts txJson.Vouts.filter({TransactionVouts: {direction: 1}});
const txTemplate = Object.assign(txJson, {
vins: txJson.Vouts.filter((vout) => vout.TransactionVouts.direction === 0),
vouts: txJson.Vouts.filter((vout) => vout.TransactionVouts.direction === 1),
});
console.log(transaction.Vouts.length);
txTemplate.blockTime = transaction.Block.time.toUTCString();
res.render('transaction', {

20
views/transaction.pug

@ -7,12 +7,18 @@ block content @@ -7,12 +7,18 @@ block content
tr
td Hash
td #{transaction.txid}
h3 Block
table
tr
td Block
td Block height
td
a(href=`/block/${transaction.Block.hash}/`) #{transaction.Block.hash}
a(href=`/block/${transaction.Block.hash}/`) #{transaction.Block.height}
tr
td Block hash
td #{transaction.Block.hash}
tr
td Block time
td Time
td #{transaction.blockTime}
tr
td Confirmations
@ -47,8 +53,6 @@ block content @@ -47,8 +53,6 @@ block content
td
a(href=`/address/${address.address}/`) #{address.address}
td #{vout.value}
td
if vout.Transactions[0].TransactionVouts.direction == 0
a(href=`/transaction/${vout.Transactions[0].txid}/`) #{vout.Transactions[0].txid}
else
span No yet
td
each transaction in vout.Transactions
a(href=`/transaction/${transaction.txid}/`) #{transaction.txid}

Loading…
Cancel
Save