Skip to content

Commit

Permalink
dont index transactions on request; 0 conf tx fix
Browse files Browse the repository at this point in the history
  • Loading branch information
iquidus committed Jul 12, 2016
1 parent 79e8f6e commit 655b7ea
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 36 deletions.
89 changes: 55 additions & 34 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function route_get_block(res, blockhash) {
res.render('block', { active: 'block', block: block, confirmations: settings.confirmations, txs: 'GENESIS'});
} else {
db.get_txs(block, function(txs) {
if (txs.length > 0) {
if (txs.length > 0) {
res.render('block', { active: 'block', block: block, confirmations: settings.confirmations, txs: txs});
} else {
db.create_txs(block, function(){
Expand Down Expand Up @@ -44,30 +44,52 @@ function route_get_tx(res, txid) {
lib.get_blockcount(function(blockcount) {
res.render('tx', { active: 'tx', tx: tx, confirmations: settings.confirmations, blockcount: blockcount});
});
}
}
else {
lib.get_rawtransaction(txid, function(rtx) {
if (rtx.txid) {
db.create_tx(txid, function(err) {
if (err) {
route_get_index(res, null);
} else {
db.get_tx(txid, function(newtx) {
res.render('tx', { active: 'tx', tx: newtx, confirmations: settings.confirmations});
lib.prepare_vin(rtx, function(vin) {
lib.prepare_vout(rtx.vout, rtx.txid, vin, function(rvout, rvin) {
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,
};
res.render('tx', { active: 'tx', tx: utx, confirmations: settings.confirmations, blockcount:-1});
} else {
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) {
res.render('tx', { active: 'tx', tx: utx, confirmations: settings.confirmations, blockcount: blockcount});
});
}
});
}
});
});
} else {
route_get_index(res, null);
}
});
});
}
});
}
}

function route_get_index(res, error) {
res.render('index', { active: 'home', error: error, warning: null});
res.render('index', { active: 'home', error: error, warning: null});
}

function route_get_address(res, hash, count) {
Expand All @@ -89,10 +111,10 @@ function route_get_address(res, hash, count) {
}
});
}, function(){

res.render('address', { active: 'address', address: address, txs: txs});
});

} else {
route_get_index(res, hash + ' not found');
}
Expand All @@ -117,9 +139,9 @@ router.get('/markets/:market', function(req, res) {
exchange: settings.markets.exchange,
data: data,
};
res.render('./markets/' + market, {
active: 'markets',
marketdata: market_data,
res.render('./markets/' + market, {
active: 'markets',
marketdata: market_data,
market: market,
});
});
Expand All @@ -129,16 +151,16 @@ router.get('/markets/:market', function(req, res) {
});

router.get('/richlist', function(req, res) {
if (settings.display.richlist == true ) {
db.get_stats(settings.coin, function (stats) {
if (settings.display.richlist == true ) {
db.get_stats(settings.coin, function (stats) {
db.get_richlist(settings.coin, function(richlist){
//console.log(richlist);
if (richlist) {
db.get_distribution(richlist, stats, function(distribution) {
//console.log(distribution);
res.render('richlist', {
active: 'richlist',
balance: richlist.balance,
res.render('richlist', {
active: 'richlist',
balance: richlist.balance,
received: richlist.received,
stats: stats,
dista: distribution.t_1_25,
Expand All @@ -155,7 +177,7 @@ router.get('/richlist', function(req, res) {
route_get_index(res, null);
}
});
});
});
} else {
route_get_index(res, null);
}
Expand All @@ -166,7 +188,7 @@ router.get('/reward', function(req, res){
console.log(stats);
db.get_heavy(settings.coin, function (heavy) {
//heavy = heavy;
var votes = heavy.votes;
var votes = heavy.votes;
votes.sort(function (a,b) {
if (a.count < b.count) {
return -1;
Expand All @@ -176,7 +198,7 @@ router.get('/reward', function(req, res){
return 0;
}
});

res.render('reward', { active: 'reward', stats: stats, heavy: heavy, votes: heavy.votes });
});
//});
Expand Down Expand Up @@ -204,7 +226,7 @@ router.post('/search', function(req, res) {
if (query == settings.genesis_tx) {
res.redirect('/block/' + settings.genesis_block);
} else {
db.get_tx(query, function(tx) {
db.get_tx(query, function(tx) {
if (tx) {
res.redirect('/tx/' +tx.txid);
} else {
Expand Down Expand Up @@ -237,11 +259,11 @@ router.post('/search', function(req, res) {

router.get('/qr/:string', function(req, res) {
if (req.param('string')) {
var address = qr.image(req.param('string'), {
type: 'png',
size: 4,
margin: 1,
ec_level: 'M'
var address = qr.image(req.param('string'), {
type: 'png',
size: 4,
margin: 1,
ec_level: 'M'
});
res.type('png');
address.pipe(res);
Expand All @@ -267,9 +289,9 @@ router.get('/ext/summary', function(req, res) {
db.get_stats(settings.coin, function (stats) {
if (hashrate == 'There was an error. Check your console.') {
hashrate = 0;
}
res.send({ data: [{
difficulty: difficulty,
}
res.send({ data: [{
difficulty: difficulty,
difficultyHybrid: difficultyHybrid,
supply: stats.supply,
hashrate: hashrate,
Expand All @@ -284,4 +306,3 @@ router.get('/ext/summary', function(req, res) {
});
});
module.exports = router;

3 changes: 1 addition & 2 deletions views/tx.jade
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ block content
th #{settings.locale.timestamp}
th
tbody
- var confirms = (blockcount - tx.blockindex) + 1;
- var confirms = (blockcount - tx.blockindex);
if confirms >= confirmations
tr.success
td #{confirms}
Expand Down Expand Up @@ -111,4 +111,3 @@ block content
tr.hidden-lg.hidden-md
td.success #{ramount.toFixed(8)} #{settings.symbol}
.footer-padding

0 comments on commit 655b7ea

Please sign in to comment.