mirror of
https://github.com/GOSTSec/gostexplr
synced 2025-01-30 08:24:23 +00:00
Promises turned to async/await
This commit is contained in:
parent
edb9cbe06e
commit
8fc53880a2
@ -3,13 +3,13 @@ var express = require('express');
|
||||
var router = express.Router();
|
||||
|
||||
/* GET home page. */
|
||||
router.get('/:address', function(req, res, next) {
|
||||
router.get('/:address', async function(req, res, next) {
|
||||
|
||||
const address = encodeURI(req.params.address);
|
||||
const addrss = encodeURI(req.params.address);
|
||||
|
||||
models.Address.findOne({
|
||||
const address = await models.Address.findOne({
|
||||
where: {
|
||||
address,
|
||||
address: addrss,
|
||||
},
|
||||
include: {
|
||||
model: models.Vout,
|
||||
@ -17,18 +17,17 @@ router.get('/:address', function(req, res, next) {
|
||||
model: models.Transaction,
|
||||
},
|
||||
},
|
||||
})
|
||||
.then((address) => {
|
||||
if (address === null) {
|
||||
res.status(404).render('404');
|
||||
return;
|
||||
}
|
||||
const txes = [];
|
||||
address.Vouts.forEach((vout) => txes.push(vout.Transaction.txid));
|
||||
res.render('address', {
|
||||
address: address.address,
|
||||
txes,
|
||||
});
|
||||
});
|
||||
|
||||
if (address === null) {
|
||||
res.status(404).render('404');
|
||||
return;
|
||||
}
|
||||
const txes = [];
|
||||
address.Vouts.forEach((vout) => txes.push(vout.Transaction.txid));
|
||||
res.render('address', {
|
||||
address: address.address,
|
||||
txes,
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -3,9 +3,9 @@ var express = require('express');
|
||||
var router = express.Router();
|
||||
|
||||
/* GET home page. */
|
||||
router.get('/:hash', function(req, res, next) {
|
||||
router.get('/:hash', async function(req, res, next) {
|
||||
const hash = encodeURI(req.params.hash);
|
||||
models.Block.findOne({
|
||||
const block = await models.Block.findOne({
|
||||
where: {
|
||||
hash,
|
||||
},
|
||||
@ -13,16 +13,15 @@ router.get('/:hash', function(req, res, next) {
|
||||
model: models.Transaction,
|
||||
},
|
||||
})
|
||||
.then((block) => {
|
||||
if (block === null) {
|
||||
res.status(404).render('404');
|
||||
return;
|
||||
}
|
||||
block.dataValues.time = block.time.toUTCString();
|
||||
res.render('block', {
|
||||
block,
|
||||
});
|
||||
if (block === null) {
|
||||
res.status(404).render('404');
|
||||
return;
|
||||
}
|
||||
block.dataValues.time = block.time.toUTCString();
|
||||
res.render('block', {
|
||||
block,
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
@ -3,17 +3,15 @@ var express = require('express');
|
||||
var router = express.Router();
|
||||
|
||||
/* GET home page. */
|
||||
router.get('/', function(req, res, next) {
|
||||
models.Block.findAll({
|
||||
router.get('/', async function(req, res, next) {
|
||||
|
||||
const blocks = await models.Block.findAll({
|
||||
order: [['height', 'DESC']],
|
||||
limit: 30,
|
||||
})
|
||||
.then((blocks) => {
|
||||
res.render('index', {
|
||||
blocks,
|
||||
});
|
||||
});
|
||||
|
||||
res.render('index', {
|
||||
blocks,
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
@ -3,44 +3,43 @@ var express = require('express');
|
||||
var router = express.Router();
|
||||
|
||||
/* GET home page. */
|
||||
router.post('/', function(req, res, next) {
|
||||
router.post('/', async function(req, res, next) {
|
||||
|
||||
const search = encodeURI(req.body.search);
|
||||
|
||||
models.Address.findOne({
|
||||
// looking for address
|
||||
const address = await models.Address.findOne({
|
||||
where: {
|
||||
address: search,
|
||||
},
|
||||
})
|
||||
.then((address) => {
|
||||
if (address) {
|
||||
res.redirect(`/address/${address.address}`);
|
||||
return;
|
||||
}
|
||||
models.Transaction.findOne({
|
||||
where: {
|
||||
txid: search,
|
||||
},
|
||||
})
|
||||
.then((transaction) => {
|
||||
if (transaction) {
|
||||
res.redirect(`/transaction/${transaction.txid}`);
|
||||
return;
|
||||
}
|
||||
models.Block.findOne({
|
||||
where: {
|
||||
hash: search,
|
||||
},
|
||||
})
|
||||
.then((block) => {
|
||||
if (block) {
|
||||
res.redirect(`/block/${block.hash}`);
|
||||
return;
|
||||
}
|
||||
res.status(404).render('404');
|
||||
});
|
||||
});
|
||||
});
|
||||
if (address) {
|
||||
res.redirect(`/address/${address.address}`);
|
||||
return;
|
||||
}
|
||||
|
||||
// looking for transaction
|
||||
const transaction = await models.Transaction.findOne({
|
||||
where: {
|
||||
txid: search,
|
||||
},
|
||||
});
|
||||
if (transaction) {
|
||||
res.redirect(`/transaction/${transaction.txid}`);
|
||||
return;
|
||||
}
|
||||
|
||||
// looking for block
|
||||
const block = await models.Block.findOne({
|
||||
where: {
|
||||
hash: search,
|
||||
},
|
||||
});
|
||||
if (block) {
|
||||
res.redirect(`/block/${block.hash}`);
|
||||
return;
|
||||
}
|
||||
res.status(404).render('404');
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
@ -3,10 +3,10 @@ var express = require('express');
|
||||
var router = express.Router();
|
||||
|
||||
/* GET home page. */
|
||||
router.get('/:txid', function(req, res, next) {
|
||||
router.get('/:txid', async function(req, res, next) {
|
||||
const txid = encodeURI(req.params.txid);
|
||||
|
||||
models.Transaction.findOne({
|
||||
const transaction = await models.Transaction.findOne({
|
||||
where: {
|
||||
txid,
|
||||
},
|
||||
@ -22,27 +22,24 @@ router.get('/:txid', function(req, res, next) {
|
||||
model: models.Transaction,
|
||||
as: 'txtx',
|
||||
}],
|
||||
})
|
||||
.then((transaction) => {
|
||||
if (transaction === null) {
|
||||
res.status(404).render('404');
|
||||
return;
|
||||
}
|
||||
const vouts = [];
|
||||
transaction.Vouts.forEach((vout) => {
|
||||
vout.Addresses.forEach((address) => {
|
||||
vouts.push({
|
||||
address: address.address,
|
||||
value: vout.value,
|
||||
});
|
||||
});
|
||||
if (transaction === null) {
|
||||
res.status(404).render('404');
|
||||
return;
|
||||
}
|
||||
const vouts = [];
|
||||
transaction.Vouts.forEach((vout) => {
|
||||
vout.Addresses.forEach((address) => {
|
||||
vouts.push({
|
||||
address: address.address,
|
||||
value: vout.value,
|
||||
});
|
||||
});
|
||||
res.render('transaction', {
|
||||
transaction,
|
||||
vouts,
|
||||
});
|
||||
});
|
||||
|
||||
res.render('transaction', {
|
||||
transaction,
|
||||
vouts,
|
||||
});
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
Loading…
x
Reference in New Issue
Block a user