Skip to content
Permalink
Browse files

Movement: Use new lasttxsajax call and remove old code

  • Loading branch information
TheHolyRoger committed Dec 24, 2019
1 parent b810eab commit a57e734a6887697821fe1c34d8268776bab03d8c
Showing with 56 additions and 48 deletions.
  1. +4 −0 .gitignore
  2. +8 −9 app.js
  3. +3 −13 lib/database.js
  4. +1 −1 views/index.jade
  5. +3 −3 views/info.jade
  6. +37 −22 views/movement.jade
@@ -30,3 +30,7 @@ settings.json
*.ico
*.png


.DS_Store

package-lock.json
17 app.js
@@ -143,20 +143,19 @@ app.use('/ext/getdistribution', function(req,res){
});
});

app.use('/ext/getlasttxs/:min', function(req,res){
db.get_last_txs(settings.index.last_txs, (req.params.min * 100000000), function(txs){
res.send({data: txs});
});
});

app.use('/ext/getlasttxsajax', function(req,res){
app.use('/ext/getlasttxsajax/:min', function(req,res){
if(typeof req.query.length === 'undefined' || isNaN(req.query.length) || req.query.length > settings.index.last_txs){
req.query.length = settings.index.last_txs;
}
if(typeof req.query.start === 'undefined' || isNaN(req.query.start) || req.query.start < 0){
req.query.start = 0;
req.query.start = 0;
}
if(typeof req.params.min === 'undefined' || isNaN(req.params.min ) || req.params.min < 0){
req.params.min = 0;
} else {
req.params.min = (req.params.min * 100000000);
}
db.get_last_txs_ajax(req.query.start, req.query.length,function(txs, count){
db.get_last_txs_ajax(req.query.start, req.query.length, req.params.min,function(txs, count){
var data = [];
for(i=0; i<txs.length; i++){
var row = [];
@@ -481,19 +481,9 @@ module.exports = {
});
},

get_last_txs: function(count, min, cb) {
Tx.find({'total': {$gt: min}}).sort({_id: 'desc'}).limit(count).exec(function(err, txs){
if (err) {
return cb(err);
} else {
return cb(txs);
}
});
},

get_last_txs_ajax: function(start, length, cb) {
Tx.countDocuments({'total': {$gt: 1}}, function(err, count){
Tx.find({'total': {$gt: 1}}).sort({blockindex: 'desc'}).skip(Number(start)).limit(Number(length)).exec(function(err, txs){
get_last_txs_ajax: function(start, length, min, cb) {
Tx.countDocuments({'total': {$gt: min}}, function(err, count){
Tx.find({'total': {$gt: min}}).sort({blockindex: 'desc'}).skip(Number(start)).limit(Number(length)).exec(function(err, txs){
if (err) {
return cb(err);
} else {
@@ -52,7 +52,7 @@ block content
serverSide: true,
iDisplayLength: displayLengthMax,
lengthMenu: lengthMenuOpts,
ajax: '/ext/getlasttxsajax',
ajax: '/ext/getlasttxsajax/1',
rowCallback: function(row, data, index) {
var blockindex = data[0]; //variables for better readability
var blockhash = data[1]; //variables for better readability
@@ -108,10 +108,10 @@ block content
*Returns current balance of given address*
[#{address}/ext/getbalance/#{hashes.address}](/ext/getbalance/#{hashes.address})

* **getlasttxs (/ext/getlasttxs/count/min)**
*Returns last [count] transactions greater than [min]*
* **getlasttxsajax (/ext/getlasttxsajax/min)**
*Returns last transactions greater than [min]*
*Note: returned values are in satoshis*
[#{address}/ext/getlasttxs/10/100](/ext/getlasttxs/10/100)
[#{address}/ext/getlasttxsajax/100](/ext/getlasttxsajax/100)

------

@@ -2,6 +2,19 @@ extends layout

block content
script.
var setting_maxTxCount = parseInt("#{settings.index.last_txs}");
var lengthMenuOpts = [];
var lengthMenuOptsAdd = [ 10, 25, 50, 75, 100, 250, 500, 1000 ];
for (i=0; i < lengthMenuOptsAdd.length; i++) {
if (setting_maxTxCount >= lengthMenuOptsAdd[i]) {
lengthMenuOpts.push(lengthMenuOptsAdd[i]);
}
}
if (setting_maxTxCount < 10) {
var displayLengthMax = setting_maxTxCount;
} else {
var displayLengthMax = 10;
}
var rplot;
var colors = [ "#0071bc" ];
$(document).ready(function(){
@@ -35,31 +48,33 @@ block content
searching: false,
ordering: false,
//responsive: true,
lengthChange: false,
lengthChange: true,
processing: true,
serverSide: true,
iDisplayLength: displayLengthMax,
lengthMenu: lengthMenuOpts,
//processing: true,
ajax: {
url: '/ext/getlasttxs/#{min_amount}',
dataSrc: function ( json ) {
for ( var i=0;i<json.data.length; i++ ) {
json.data[i]['timestamp'] = format_unixtime(json.data[i]['timestamp']);
json.data[i]['txid'] = "<a href='/tx/" + json.data[i]['txid'] + "' target='_blank'>" + json.data[i]['txid'] + "</a>"
var amount = json.data[i]['total'] / 100000000;
if (amount > '#{flagb}') {
json .data[i]['total'] = "<label class='label label-danger'>" + amount.toLocaleString('en') + "</label>";
} else if (amount > '#{flaga}') {
json .data[i]['total'] = "<label class='label label-warning'>" + amount.toLocaleString('en') + "</label>";
} else {
json .data[i]['total'] = "<label class='label label-success'>" + amount.toLocaleString('en') + "</label>";
}
}
return json.data;
ajax: '/ext/getlasttxsajax/#{min_amount}',
rowCallback: function(row, data, index) {
var blockindex = data[0]; //variables for better readability
var blockhash = data[1]; //variables for better readability
var txhash = data[2]; //variables for better readability
var outputs = data[3]; //variables for better readability
var amount = (data[4] / 100000000); //variables for better readability
var amountParts = amount.toLocaleString('en',{'minimumFractionDigits':2,'maximumFractionDigits':8,'useGrouping':true}).split('.');
var amountStr = amountParts[0] + '.<span class="decimal">' + amountParts[1] + '</span>';
var timestamp = data[5]; //variables for better readability
if (amount > '#{flagb}') {
var total = "<label class='label label-danger'>" + amountStr + "</label>";
} else if (amount > '#{flaga}') {
var total = "<label class='label label-warning'>" + amountStr + "</label>";
} else {
var total = "<label class='label label-success'>" + amountStr + "</label>";
}
$("td:eq(0)", row).html(timestamp);
$("td:eq(1)", row).html('<a href="/tx/' + txhash + '">' + txhash + '</a>');
$("td:eq(2)", row).html(total);
},
columns: [
{ data: 'timestamp', width: '25%' },
{ data: 'txid', width: '60%' },
{ data: 'total', width: '15%' },
]
});
setInterval( function () {
rtable.api().ajax.reload(null, false);

0 comments on commit a57e734

Please sign in to comment.
You can’t perform that action at this time.