2019-05-27 10:33:22 -07:00
|
|
|
var express = require('express')
|
2020-11-19 21:37:42 -07:00
|
|
|
, router = express.Router()
|
|
|
|
|
, settings = require('../lib/settings')
|
|
|
|
|
, locale = require('../lib/locale')
|
|
|
|
|
, db = require('../lib/database')
|
|
|
|
|
, lib = require('../lib/explorer')
|
|
|
|
|
, qr = require('qr-image');
|
2019-05-27 10:33:22 -07:00
|
|
|
|
|
|
|
|
function route_get_block(res, blockhash) {
|
|
|
|
|
lib.get_block(blockhash, function (block) {
|
2020-12-07 21:32:43 -07:00
|
|
|
if (block && block != 'There was an error. Check your console.') {
|
2019-05-27 10:33:22 -07:00
|
|
|
if (blockhash == settings.genesis_block) {
|
2020-12-05 12:39:36 -07:00
|
|
|
res.render('block', { active: 'block', block: block, confirmations: settings.confirmations, txs: 'GENESIS', showSync: db.check_show_sync_message()});
|
2019-05-27 10:33:22 -07:00
|
|
|
} else {
|
|
|
|
|
db.get_txs(block, function(txs) {
|
|
|
|
|
if (txs.length > 0) {
|
2020-12-05 12:39:36 -07:00
|
|
|
res.render('block', { active: 'block', block: block, confirmations: settings.confirmations, txs: txs, showSync: db.check_show_sync_message()});
|
2019-05-27 10:33:22 -07:00
|
|
|
} else {
|
|
|
|
|
db.create_txs(block, function(){
|
|
|
|
|
db.get_txs(block, function(ntxs) {
|
|
|
|
|
if (ntxs.length > 0) {
|
2020-12-05 12:39:36 -07:00
|
|
|
res.render('block', { active: 'block', block: block, confirmations: settings.confirmations, txs: ntxs, showSync: db.check_show_sync_message()});
|
2019-05-27 10:33:22 -07:00
|
|
|
} else {
|
|
|
|
|
route_get_index(res, 'Block not found: ' + blockhash);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2020-11-23 20:20:58 -07:00
|
|
|
if (!isNaN(blockhash)) {
|
|
|
|
|
var height = blockhash;
|
|
|
|
|
lib.get_blockhash(height, function(hash) {
|
2020-12-07 21:32:43 -07:00
|
|
|
if (hash && hash != 'There was an error. Check your console.') {
|
2020-11-23 20:20:58 -07:00
|
|
|
res.redirect('/block/' + hash);
|
|
|
|
|
} else {
|
|
|
|
|
route_get_index(res, 'Block not found: ' + blockhash);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
route_get_index(res, 'Block not found: ' + blockhash);
|
|
|
|
|
}
|
2019-05-27 10:33:22 -07:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
/* GET functions */
|
|
|
|
|
|
|
|
|
|
function route_get_tx(res, txid) {
|
|
|
|
|
if (txid == settings.genesis_tx) {
|
|
|
|
|
route_get_block(res, settings.genesis_block);
|
|
|
|
|
} else {
|
|
|
|
|
db.get_tx(txid, function(tx) {
|
|
|
|
|
if (tx) {
|
|
|
|
|
lib.get_blockcount(function(blockcount) {
|
2020-12-23 18:40:10 -07:00
|
|
|
if (settings.display.claim_address) {
|
|
|
|
|
db.populate_claim_address_names(tx, function(tx) {
|
|
|
|
|
res.render('tx', { active: 'tx', tx: tx, confirmations: settings.confirmations, blockcount: (blockcount ? blockcount : 0), showSync: db.check_show_sync_message()});
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
res.render('tx', { active: 'tx', tx: tx, confirmations: settings.confirmations, blockcount: (blockcount ? blockcount : 0), showSync: db.check_show_sync_message()});
|
|
|
|
|
}
|
2019-05-27 10:33:22 -07:00
|
|
|
});
|
2020-12-23 18:40:10 -07:00
|
|
|
} else {
|
2019-05-27 10:33:22 -07:00
|
|
|
lib.get_rawtransaction(txid, function(rtx) {
|
2020-12-07 21:32:43 -07:00
|
|
|
if (rtx && rtx.txid) {
|
2019-05-27 10:33:22 -07:00
|
|
|
lib.prepare_vin(rtx, function(vin) {
|
2019-10-17 22:06:30 -06:00
|
|
|
lib.prepare_vout(rtx.vout, rtx.txid, vin, ((typeof rtx.vjoinsplit === 'undefined' || rtx.vjoinsplit == null) ? [] : rtx.vjoinsplit), function(rvout, rvin) {
|
2019-05-27 10:33:22 -07:00
|
|
|
lib.calculate_total(rvout, function(total){
|
|
|
|
|
if (!rtx.confirmations > 0) {
|
|
|
|
|
var utx = {
|
|
|
|
|
txid: rtx.txid,
|
|
|
|
|
vin: rvin,
|
|
|
|
|
vout: rvout,
|
|
|
|
|
total: total.toFixed(8),
|
|
|
|
|
timestamp: rtx.time,
|
|
|
|
|
blockhash: '-',
|
|
|
|
|
blockindex: -1,
|
|
|
|
|
};
|
2020-12-23 18:40:10 -07:00
|
|
|
|
|
|
|
|
if (settings.display.claim_address) {
|
|
|
|
|
db.populate_claim_address_names(utx, function(utx) {
|
|
|
|
|
res.render('tx', { active: 'tx', tx: utx, confirmations: settings.confirmations, blockcount:-1, showSync: db.check_show_sync_message()});
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
res.render('tx', { active: 'tx', tx: utx, confirmations: settings.confirmations, blockcount:-1, showSync: db.check_show_sync_message()});
|
|
|
|
|
}
|
2019-05-27 10:33:22 -07:00
|
|
|
} else {
|
2020-12-08 21:56:01 -07:00
|
|
|
// check if blockheight exists
|
|
|
|
|
if (!rtx.blockheight && rtx.blockhash) {
|
|
|
|
|
// blockheight not found so look up the block
|
|
|
|
|
lib.get_block(rtx.blockhash, function(block) {
|
|
|
|
|
if (block && block != 'There was an error. Check your console.') {
|
|
|
|
|
// create the tx object before rendering
|
|
|
|
|
var utx = {
|
|
|
|
|
txid: rtx.txid,
|
|
|
|
|
vin: rvin,
|
|
|
|
|
vout: rvout,
|
|
|
|
|
total: total.toFixed(8),
|
|
|
|
|
timestamp: rtx.time,
|
|
|
|
|
blockhash: rtx.blockhash,
|
|
|
|
|
blockindex: block.height,
|
|
|
|
|
};
|
|
|
|
|
lib.get_blockcount(function(blockcount) {
|
2020-12-23 18:40:10 -07:00
|
|
|
if (settings.display.claim_address) {
|
|
|
|
|
db.populate_claim_address_names(utx, function(utx) {
|
|
|
|
|
res.render('tx', { active: 'tx', tx: utx, confirmations: settings.confirmations, blockcount: (blockcount ? blockcount : 0), showSync: db.check_show_sync_message()});
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
res.render('tx', { active: 'tx', tx: utx, confirmations: settings.confirmations, blockcount: (blockcount ? blockcount : 0), showSync: db.check_show_sync_message()});
|
|
|
|
|
}
|
2020-12-08 21:56:01 -07:00
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
// cannot load tx
|
|
|
|
|
route_get_index(res, null);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
// create the tx object before rendering
|
|
|
|
|
var utx = {
|
|
|
|
|
txid: rtx.txid,
|
|
|
|
|
vin: rvin,
|
|
|
|
|
vout: rvout,
|
|
|
|
|
total: total.toFixed(8),
|
|
|
|
|
timestamp: rtx.time,
|
|
|
|
|
blockhash: rtx.blockhash,
|
|
|
|
|
blockindex: rtx.blockheight,
|
|
|
|
|
};
|
|
|
|
|
lib.get_blockcount(function(blockcount) {
|
2020-12-23 18:40:10 -07:00
|
|
|
if (settings.display.claim_address) {
|
|
|
|
|
db.populate_claim_address_names(utx, function(utx) {
|
|
|
|
|
res.render('tx', { active: 'tx', tx: utx, confirmations: settings.confirmations, blockcount: (blockcount ? blockcount : 0), showSync: db.check_show_sync_message()});
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
res.render('tx', { active: 'tx', tx: utx, confirmations: settings.confirmations, blockcount: (blockcount ? blockcount : 0), showSync: db.check_show_sync_message()});
|
|
|
|
|
}
|
2020-12-08 21:56:01 -07:00
|
|
|
});
|
|
|
|
|
}
|
2019-05-27 10:33:22 -07:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
route_get_index(res, null);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function route_get_index(res, error) {
|
2020-12-31 15:19:48 -07:00
|
|
|
// check if index page should show last updated date
|
|
|
|
|
if (settings.index.show_last_updated == true) {
|
|
|
|
|
// lookup last updated date
|
|
|
|
|
db.get_stats(settings.coin, function (stats) {
|
|
|
|
|
res.render('index', { active: 'home', error: error, last_updated: stats.blockchain_last_updated, showSync: db.check_show_sync_message()});
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
// skip lookup up the last updated date and display the page now
|
|
|
|
|
res.render('index', { active: 'home', error: error, last_updated: null, showSync: db.check_show_sync_message()});
|
|
|
|
|
}
|
2019-05-27 10:33:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function route_get_address(res, hash, count) {
|
2019-10-17 21:51:13 -06:00
|
|
|
db.get_address(hash, false, function(address) {
|
2019-05-27 10:33:22 -07:00
|
|
|
if (address) {
|
2020-12-23 18:40:10 -07:00
|
|
|
res.render('address', { active: 'address', address: address, showSync: db.check_show_sync_message()});
|
2019-05-27 10:33:22 -07:00
|
|
|
} else {
|
|
|
|
|
route_get_index(res, hash + ' not found');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-23 18:40:10 -07:00
|
|
|
function route_get_claim_form(res, hash) {
|
|
|
|
|
// check if claiming addresses is enabled
|
|
|
|
|
if (settings.display.claim_address) {
|
2020-12-26 22:01:36 -07:00
|
|
|
// check if a hash was passed in
|
|
|
|
|
if (hash == null || hash == '') {
|
|
|
|
|
// no hash so just load the claim page without an address
|
|
|
|
|
res.render("claim_address", { active: "claim-address", hash: hash, claim_name: '', showSync: db.check_show_sync_message()});
|
|
|
|
|
} else {
|
|
|
|
|
// lookup hash in the address collection
|
|
|
|
|
db.get_address(hash, false, function(address) {
|
|
|
|
|
// load the claim page regardless of whether the address exists or not
|
|
|
|
|
res.render("claim_address", { active: "claim-address", hash: hash, claim_name: (address == null || address.name == null ? '' : address.name), showSync: db.check_show_sync_message()});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} else
|
2020-12-23 18:40:10 -07:00
|
|
|
route_get_address(res, hash, settings.txcount);
|
2020-11-22 14:39:10 -07:00
|
|
|
}
|
|
|
|
|
|
2019-05-27 10:33:22 -07:00
|
|
|
/* GET home page. */
|
|
|
|
|
router.get('/', function(req, res) {
|
|
|
|
|
route_get_index(res, null);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
router.get('/info', function(req, res) {
|
2020-12-05 12:39:36 -07:00
|
|
|
res.render('info', { active: 'info', address: settings.address, hashes: settings.api, showSync: db.check_show_sync_message() });
|
2019-05-27 10:33:22 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
router.get('/markets/:market', function(req, res) {
|
2020-12-31 15:19:48 -07:00
|
|
|
// ensure markets page is enabled
|
|
|
|
|
if (settings.display.markets == true) {
|
|
|
|
|
var market_id = req.params['market'];
|
|
|
|
|
|
|
|
|
|
if (settings.markets.enabled.indexOf(market_id) != -1) {
|
|
|
|
|
// lookup market data
|
|
|
|
|
db.get_market(market_id, function(data) {
|
|
|
|
|
// load market data
|
|
|
|
|
var market_data = require('../lib/markets/' + market_id);
|
|
|
|
|
// check if markets page should show last updated date
|
|
|
|
|
if (settings.markets_page.show_last_updated == true) {
|
|
|
|
|
// lookup last updated date
|
|
|
|
|
db.get_stats(settings.coin, function (stats) {
|
|
|
|
|
res.render('./market', {
|
|
|
|
|
active: 'markets',
|
|
|
|
|
marketdata: {
|
|
|
|
|
market_name: (market_data.market_name == null ? '' : market_data.market_name),
|
|
|
|
|
market_logo: (market_data.market_logo == null ? '' : market_data.market_logo),
|
|
|
|
|
coin: settings.markets.coin,
|
|
|
|
|
exchange: settings.markets.exchange,
|
|
|
|
|
data: data,
|
|
|
|
|
},
|
|
|
|
|
market: market_id,
|
|
|
|
|
last_updated: stats.markets_last_updated,
|
|
|
|
|
showSync: db.check_show_sync_message()
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
// skip lookup up the last updated date and display the page now
|
|
|
|
|
res.render('./market', {
|
|
|
|
|
active: 'markets',
|
|
|
|
|
marketdata: {
|
|
|
|
|
market_name: (market_data.market_name == null ? '' : market_data.market_name),
|
|
|
|
|
market_logo: (market_data.market_logo == null ? '' : market_data.market_logo),
|
|
|
|
|
coin: settings.markets.coin,
|
|
|
|
|
exchange: settings.markets.exchange,
|
|
|
|
|
data: data,
|
|
|
|
|
},
|
|
|
|
|
market: market_id,
|
|
|
|
|
last_updated: null,
|
|
|
|
|
showSync: db.check_show_sync_message()
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-05-27 10:33:22 -07:00
|
|
|
});
|
2020-12-31 15:19:48 -07:00
|
|
|
} else {
|
|
|
|
|
// selected market is not enabled so default to the index page
|
|
|
|
|
route_get_index(res, null);
|
|
|
|
|
}
|
2019-05-27 10:33:22 -07:00
|
|
|
} else {
|
2020-12-31 15:19:48 -07:00
|
|
|
// markets page is not enabled so default to the index page
|
2019-05-27 10:33:22 -07:00
|
|
|
route_get_index(res, null);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
router.get('/richlist', function(req, res) {
|
2020-12-31 15:19:48 -07:00
|
|
|
// ensure richlist page is enabled
|
|
|
|
|
if (settings.display.richlist == true) {
|
2019-05-27 10:33:22 -07:00
|
|
|
db.get_stats(settings.coin, function (stats) {
|
2020-12-31 15:19:48 -07:00
|
|
|
db.get_richlist(settings.coin, function(richlist) {
|
2019-05-27 10:33:22 -07:00
|
|
|
if (richlist) {
|
|
|
|
|
db.get_distribution(richlist, stats, function(distribution) {
|
|
|
|
|
res.render('richlist', {
|
|
|
|
|
active: 'richlist',
|
|
|
|
|
balance: richlist.balance,
|
|
|
|
|
received: richlist.received,
|
|
|
|
|
stats: stats,
|
|
|
|
|
dista: distribution.t_1_25,
|
|
|
|
|
distb: distribution.t_26_50,
|
|
|
|
|
distc: distribution.t_51_75,
|
|
|
|
|
distd: distribution.t_76_100,
|
|
|
|
|
diste: distribution.t_101plus,
|
|
|
|
|
show_dist: settings.richlist.distribution,
|
|
|
|
|
show_received: settings.richlist.received,
|
|
|
|
|
show_balance: settings.richlist.balance,
|
2020-12-31 15:19:48 -07:00
|
|
|
last_updated: (settings.richlist_page.show_last_updated == true ? stats.richlist_last_updated : null),
|
|
|
|
|
showSync: db.check_show_sync_message()
|
2019-05-27 10:33:22 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
} else {
|
2020-12-31 15:19:48 -07:00
|
|
|
// richlist data not found so default to the index page
|
2019-05-27 10:33:22 -07:00
|
|
|
route_get_index(res, null);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
} else {
|
2020-12-31 15:19:48 -07:00
|
|
|
// richlist page is not enabled so default to the index page
|
2019-05-27 10:33:22 -07:00
|
|
|
route_get_index(res, null);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
router.get('/movement', function(req, res) {
|
2020-12-31 15:19:48 -07:00
|
|
|
// ensure movement page is enabled
|
|
|
|
|
if (settings.display.movement == true) {
|
|
|
|
|
// check if movement page should show last updated date
|
|
|
|
|
if (settings.movement_page.show_last_updated == true) {
|
|
|
|
|
// lookup last updated date
|
|
|
|
|
db.get_stats(settings.coin, function (stats) {
|
|
|
|
|
res.render('movement', {active: 'movement', flaga: settings.movement.low_flag, flagb: settings.movement.high_flag, min_amount:settings.movement.min_amount, last_updated: stats.blockchain_last_updated, showSync: db.check_show_sync_message()});
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
// skip lookup up the last updated date and display the page now
|
|
|
|
|
res.render('movement', {active: 'movement', flaga: settings.movement.low_flag, flagb: settings.movement.high_flag, min_amount:settings.movement.min_amount, last_updated: null, showSync: db.check_show_sync_message()});
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// movement page is not enabled so default to the index page
|
|
|
|
|
route_get_index(res, null);
|
|
|
|
|
}
|
2019-05-27 10:33:22 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
router.get('/network', function(req, res) {
|
2020-12-31 15:19:48 -07:00
|
|
|
// ensure network page is enabled
|
|
|
|
|
if (settings.display.network == true) {
|
|
|
|
|
// check if network page should show last updated date
|
|
|
|
|
if (settings.network_page.show_last_updated == true) {
|
|
|
|
|
// lookup last updated date
|
|
|
|
|
db.get_stats(settings.coin, function (stats) {
|
|
|
|
|
res.render('network', {active: 'network', last_updated: stats.network_last_updated, showSync: db.check_show_sync_message()});
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
// skip lookup up the last updated date and display the page now
|
|
|
|
|
res.render('network', {active: 'network', last_updated: null, showSync: db.check_show_sync_message()});
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// network page is not enabled so default to the index page
|
|
|
|
|
route_get_index(res, null);
|
|
|
|
|
}
|
2019-05-27 10:33:22 -07:00
|
|
|
});
|
|
|
|
|
|
2020-12-30 18:22:02 -07:00
|
|
|
// masternode list page
|
|
|
|
|
router.get('/masternodes', function(req, res) {
|
|
|
|
|
// ensure masternode page is enabled
|
|
|
|
|
if (settings.display.masternodes == true) {
|
2020-12-31 15:19:48 -07:00
|
|
|
// check if masternodes page should show last updated date
|
|
|
|
|
if (settings.masternodes_page.show_last_updated == true) {
|
|
|
|
|
// lookup last updated date
|
|
|
|
|
db.get_stats(settings.coin, function (stats) {
|
|
|
|
|
res.render('masternodes', {active: 'masternodes', last_updated: stats.masternodes_last_updated, showSync: db.check_show_sync_message()});
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
// skip lookup up the last updated date and display the page now
|
|
|
|
|
res.render('masternodes', {active: 'masternodes', last_updated: null, showSync: db.check_show_sync_message()});
|
|
|
|
|
}
|
2020-12-30 18:22:02 -07:00
|
|
|
} else {
|
|
|
|
|
// masternode page is not enabled so default to the index page
|
|
|
|
|
route_get_index(res, null);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2020-12-05 13:12:35 -07:00
|
|
|
router.get('/reward', function(req, res) {
|
2020-12-31 15:19:48 -07:00
|
|
|
// ensure reward page is enabled
|
|
|
|
|
if (settings.heavy == true) {
|
2020-12-05 13:12:35 -07:00
|
|
|
db.get_stats(settings.coin, function (stats) {
|
|
|
|
|
db.get_heavy(settings.coin, function (heavy) {
|
|
|
|
|
if (!heavy)
|
|
|
|
|
heavy = { coin: settings.coin, lvote: 0, reward: 0, supply: 0, cap: 0, estnext: 0, phase: 'N/A', maxvote: 0, nextin: 'N/A', votes: [] };
|
|
|
|
|
|
|
|
|
|
var votes = heavy.votes;
|
|
|
|
|
|
2020-12-31 15:19:48 -07:00
|
|
|
votes.sort(function (a, b) {
|
|
|
|
|
if (a.count < b.count)
|
2020-12-05 13:12:35 -07:00
|
|
|
return -1;
|
2020-12-31 15:19:48 -07:00
|
|
|
else if (a.count > b.count)
|
2020-12-05 13:12:35 -07:00
|
|
|
return 1;
|
2020-12-31 15:19:48 -07:00
|
|
|
else
|
2020-12-05 13:12:35 -07:00
|
|
|
return 0;
|
|
|
|
|
});
|
2020-11-19 21:37:42 -07:00
|
|
|
|
2020-12-31 15:19:48 -07:00
|
|
|
res.render('reward', {
|
|
|
|
|
active: 'reward',
|
|
|
|
|
stats: stats,
|
|
|
|
|
heavy: heavy,
|
|
|
|
|
votes: votes,
|
|
|
|
|
last_updated: (settings.reward_page.show_last_updated == true ? stats.reward_last_updated : null),
|
|
|
|
|
showSync: db.check_show_sync_message()
|
|
|
|
|
});
|
2020-12-05 13:12:35 -07:00
|
|
|
});
|
2020-11-20 16:28:28 -07:00
|
|
|
});
|
2020-12-05 13:12:35 -07:00
|
|
|
} else {
|
2020-12-31 15:19:48 -07:00
|
|
|
// reward page is not enabled so default to the index page
|
2020-12-05 13:12:35 -07:00
|
|
|
route_get_index(res, null);
|
|
|
|
|
}
|
2019-05-27 10:33:22 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
router.get('/tx/:txid', function(req, res) {
|
|
|
|
|
route_get_tx(res, req.params.txid);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
router.get('/block/:hash', function(req, res) {
|
|
|
|
|
route_get_block(res, req.params.hash);
|
|
|
|
|
});
|
|
|
|
|
|
2020-12-26 22:01:36 -07:00
|
|
|
router.get('/claim', function(req, res) {
|
|
|
|
|
route_get_claim_form(res, '');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
router.get('/claim/:hash', function(req, res) {
|
2020-11-22 14:39:10 -07:00
|
|
|
route_get_claim_form(res, req.params.hash);
|
|
|
|
|
});
|
|
|
|
|
|
2019-05-27 10:33:22 -07:00
|
|
|
router.get('/address/:hash', function(req, res) {
|
|
|
|
|
route_get_address(res, req.params.hash, settings.txcount);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
router.get('/address/:hash/:count', function(req, res) {
|
|
|
|
|
route_get_address(res, req.params.hash, req.params.count);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
router.post('/search', function(req, res) {
|
2019-10-18 23:05:53 -06:00
|
|
|
var query = req.body.search.trim();
|
2019-05-27 10:33:22 -07:00
|
|
|
if (query.length == 64) {
|
|
|
|
|
if (query == settings.genesis_tx) {
|
|
|
|
|
res.redirect('/block/' + settings.genesis_block);
|
|
|
|
|
} else {
|
|
|
|
|
db.get_tx(query, function(tx) {
|
|
|
|
|
if (tx) {
|
2020-12-08 21:56:01 -07:00
|
|
|
res.redirect('/tx/' + tx.txid);
|
2019-05-27 10:33:22 -07:00
|
|
|
} else {
|
|
|
|
|
lib.get_block(query, function(block) {
|
2020-12-07 21:32:43 -07:00
|
|
|
if (block && block != 'There was an error. Check your console.') {
|
2019-05-27 10:33:22 -07:00
|
|
|
res.redirect('/block/' + query);
|
|
|
|
|
} else {
|
2020-12-08 21:56:01 -07:00
|
|
|
// check wallet for transaction
|
|
|
|
|
lib.get_rawtransaction(query, function(tx) {
|
|
|
|
|
if (tx && tx.txid) {
|
|
|
|
|
res.redirect('/tx/' + tx.txid);
|
|
|
|
|
} else {
|
|
|
|
|
// search found nothing so display the index page with an error msg
|
|
|
|
|
route_get_index(res, locale.ex_search_error + query );
|
|
|
|
|
}
|
|
|
|
|
});
|
2019-05-27 10:33:22 -07:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2019-10-17 21:51:13 -06:00
|
|
|
db.get_address(query, false, function(address) {
|
2019-05-27 10:33:22 -07:00
|
|
|
if (address) {
|
|
|
|
|
res.redirect('/address/' + address.a_id);
|
|
|
|
|
} else {
|
|
|
|
|
lib.get_blockhash(query, function(hash) {
|
2020-12-07 21:32:43 -07:00
|
|
|
if (hash && hash != 'There was an error. Check your console.') {
|
2019-05-27 10:33:22 -07:00
|
|
|
res.redirect('/block/' + hash);
|
|
|
|
|
} else {
|
|
|
|
|
route_get_index(res, locale.ex_search_error + query );
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
router.get('/qr/:string', function(req, res) {
|
|
|
|
|
if (req.params.string) {
|
|
|
|
|
var address = qr.image(req.params.string, {
|
|
|
|
|
type: 'png',
|
|
|
|
|
size: 4,
|
|
|
|
|
margin: 1,
|
|
|
|
|
ec_level: 'M'
|
|
|
|
|
});
|
|
|
|
|
res.type('png');
|
|
|
|
|
address.pipe(res);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
router.get('/ext/summary', function(req, res) {
|
|
|
|
|
lib.get_difficulty(function(difficulty) {
|
2020-11-22 16:07:20 -07:00
|
|
|
difficultyHybrid = '';
|
2020-12-07 21:32:43 -07:00
|
|
|
if (difficulty && difficulty['proof-of-work']) {
|
2020-11-19 21:37:42 -07:00
|
|
|
if (settings.index.difficulty == 'Hybrid') {
|
|
|
|
|
difficultyHybrid = 'POS: ' + difficulty['proof-of-stake'];
|
|
|
|
|
difficulty = 'POW: ' + difficulty['proof-of-work'];
|
|
|
|
|
} else if (settings.index.difficulty == 'POW') {
|
|
|
|
|
difficulty = difficulty['proof-of-work'];
|
|
|
|
|
} else {
|
2019-05-27 10:33:22 -07:00
|
|
|
difficulty = difficulty['proof-of-stake'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
lib.get_hashrate(function(hashrate) {
|
|
|
|
|
lib.get_connectioncount(function(connections){
|
|
|
|
|
lib.get_masternodecount(function(masternodestotal){
|
|
|
|
|
lib.get_blockcount(function(blockcount) {
|
|
|
|
|
db.get_stats(settings.coin, function (stats) {
|
2019-06-24 19:43:54 -06:00
|
|
|
if (hashrate == 'There was an error. Check your console.') {
|
|
|
|
|
hashrate = 0;
|
|
|
|
|
}
|
2020-12-07 21:32:43 -07:00
|
|
|
|
|
|
|
|
var mn_total = 0;
|
|
|
|
|
var mn_enabled = 0;
|
|
|
|
|
|
|
|
|
|
if (masternodestotal) {
|
|
|
|
|
if (masternodestotal.total)
|
|
|
|
|
mn_total = masternodestotal.total;
|
|
|
|
|
if (masternodestotal.enabled)
|
|
|
|
|
mn_enabled = masternodestotal.enabled;
|
|
|
|
|
}
|
2019-06-24 19:43:54 -06:00
|
|
|
res.send({ data: [{
|
2020-12-07 21:32:43 -07:00
|
|
|
difficulty: (difficulty ? difficulty : '-'),
|
2019-06-24 19:43:54 -06:00
|
|
|
difficultyHybrid: difficultyHybrid,
|
2020-11-23 17:20:06 -07:00
|
|
|
supply: (stats == null || stats.supply == null ? 0 : stats.supply),
|
2019-06-24 19:43:54 -06:00
|
|
|
hashrate: hashrate,
|
2020-11-23 17:20:06 -07:00
|
|
|
lastPrice: (stats == null || stats.last_price == null ? 0 : stats.last_price),
|
2020-12-07 21:32:43 -07:00
|
|
|
connections: (connections ? connections : '-'),
|
|
|
|
|
masternodeCountOnline: (masternodestotal ? mn_enabled : '-'),
|
|
|
|
|
masternodeCountOffline: (masternodestotal ? Math.floor(mn_total - mn_enabled) : '-'),
|
|
|
|
|
blockcount: (blockcount ? blockcount : '-')
|
2019-06-24 19:43:54 -06:00
|
|
|
}]});
|
2019-05-27 10:33:22 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2020-11-20 16:28:28 -07:00
|
|
|
module.exports = router;
|