Fix getlasttxs api

-Completely removed the /ext/getlasttxsajax api and replaced with /ext/getlasttxs
-Fixed record count for movement page
This commit is contained in:
joeuhren
2020-12-10 17:51:46 -07:00
parent 937c3a52ed
commit 50aeb9d321
4 changed files with 27 additions and 18 deletions
-6
View File
@@ -210,12 +210,6 @@ app.use('/ext/getlasttxs/:min', function(req, res) {
});
});
app.use('/ext/getlasttxsajax/:min', function(req, res){
db.get_last_txs(req, function(data, draw, count) {
res.json({"data":data, "draw": draw, "recordsTotal": count, "recordsFiltered": count});
});
});
app.use('/ext/getaddresstxsajax/:address', function(req,res){
req.query.length = parseInt(req.query.length);
if(isNaN(req.query.length) || req.query.length > settings.txcount){
+25 -10
View File
@@ -422,17 +422,32 @@ module.exports = {
},
get_last_txs_ajax: function(start, length, min, cb) {
// Lookup the coin stats to get the txes value which is used to determine the total # of records
Stats.findOne({coin:settings.coin}, function(err, stats) {
// Get last transactions where there is at least 1 vout
Tx.find({'total': {$gte: min}, 'vout': { $gte: { $size: 1 }}}).sort({blockindex: -1}).skip(Number(start)).limit(Number(length)).exec(function(err, txs) {
if (err) {
return cb(err);
} else {
return cb(txs, stats.txes);
}
// check if min is greater than zero
if (min > 0) {
// min is greater than zero which means we must pull record count from the txes collection
Tx.find({'total': {$gte: min}}).countDocuments(function(err, count) {
// Get last transactions where there is at least 1 vout
Tx.find({'total': {$gte: min}, 'vout': { $gte: { $size: 1 }}}).sort({blockindex: -1}).skip(Number(start)).limit(Number(length)).exec(function(err, txs) {
if (err) {
return cb(err);
} else {
return cb(txs, count);
}
});
});
});
} else {
// min is zero (shouldn't ever be negative) which means we must pull record count from the coinstats collection (pulling from txes could potentially take a long time because it would include coinbase txes)
Stats.findOne({coin:settings.coin}, function(err, stats) {
// Get last transactions where there is at least 1 vout
Tx.find({'total': {$gte: min}, 'vout': { $gte: { $size: 1 }}}).sort({blockindex: -1}).skip(Number(start)).limit(Number(length)).exec(function(err, txs) {
if (err) {
return cb(err);
} else {
return cb(txs, stats.txes);
}
});
});
}
},
get_address_txs_ajax: function(hash, start, length, cb) {
+1 -1
View File
@@ -28,7 +28,7 @@ block content
serverSide: true,
iDisplayLength: displayLengthMax,
lengthMenu: lengthMenuOpts,
ajax: '/ext/getlasttxsajax/0',
ajax: '/ext/getlasttxs/0',
language: {
paginate: {
previous: '<',
+1 -1
View File
@@ -29,7 +29,7 @@ block content
serverSide: true,
iDisplayLength: displayLengthMax,
lengthMenu: lengthMenuOpts,
ajax: '/ext/getlasttxsajax/#{min_amount}',
ajax: '/ext/getlasttxs/#{min_amount}',
language: {
paginate: {
previous: '<',