mirror of
https://github.com/GOSTSec/gostexplr
synced 2025-09-08 12:12:07 +00:00
Search by block index
This commit is contained in:
parent
c4e33e0f6f
commit
af3106b672
@ -6,10 +6,26 @@ var router = express.Router();
|
|||||||
router.post('/', async function(req, res, next) {
|
router.post('/', async function(req, res, next) {
|
||||||
|
|
||||||
let search = encodeURI(req.body.search).trim();
|
let search = encodeURI(req.body.search).trim();
|
||||||
|
|
||||||
|
// checking extra -000 in the end
|
||||||
if (search.endsWith('-000')) {
|
if (search.endsWith('-000')) {
|
||||||
search = search.slice(0, -4);
|
search = search.slice(0, -4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// checking if it is block index
|
||||||
|
const blockIndex = parseInt(search);
|
||||||
|
if (isNaN(blockIndex) === false && blockIndex.toString() === search) {
|
||||||
|
const block = await models.Block.findOne({
|
||||||
|
where: {
|
||||||
|
height: blockIndex,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (block) {
|
||||||
|
res.redirect(`/block/${block.hash}/`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// looking for address
|
// looking for address
|
||||||
const address = await models.Address.findOne({
|
const address = await models.Address.findOne({
|
||||||
where: {
|
where: {
|
||||||
@ -17,7 +33,7 @@ router.post('/', async function(req, res, next) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (address) {
|
if (address) {
|
||||||
res.redirect(`/address/${address.address}`);
|
res.redirect(`/address/${address.address}/`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,7 +44,7 @@ router.post('/', async function(req, res, next) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (transaction) {
|
if (transaction) {
|
||||||
res.redirect(`/transaction/${transaction.txid}`);
|
res.redirect(`/transaction/${transaction.txid}/`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,7 +55,7 @@ router.post('/', async function(req, res, next) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (block) {
|
if (block) {
|
||||||
res.redirect(`/block/${block.hash}`);
|
res.redirect(`/block/${block.hash}/`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
res.status(404).render('404');
|
res.status(404).render('404');
|
||||||
|
@ -12,7 +12,7 @@ html
|
|||||||
span GOSTcoin blockchain explorer
|
span GOSTcoin blockchain explorer
|
||||||
div
|
div
|
||||||
form(action="/search/", method="POST")
|
form(action="/search/", method="POST")
|
||||||
input(type="text", name="search" placeholder="Search by transaction id, block hash or address", size="68")
|
input(type="text", name="search" placeholder="Search by transaction id, block hash/index or address", size="68")
|
||||||
input(type="submit", value=">>")
|
input(type="submit", value=">>")
|
||||||
div.content
|
div.content
|
||||||
block content
|
block content
|
||||||
|
Loading…
x
Reference in New Issue
Block a user