API: get all info about blocks and transactions in list methods. Fix transaction list on homepage
This commit is contained in:
parent
92cf429e64
commit
36c3466f32
|
@ -3,9 +3,10 @@
|
|||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
var mongoose = require('mongoose'),
|
||||
Block = mongoose.model('Block'),
|
||||
common = require('./common');
|
||||
var mongoose = require('mongoose'),
|
||||
Block = mongoose.model('Block'),
|
||||
common = require('./common'),
|
||||
async = require('async');
|
||||
|
||||
|
||||
/**
|
||||
|
@ -47,6 +48,16 @@ exports.blockindex = function(req, res, next, height) {
|
|||
});
|
||||
};
|
||||
|
||||
var getBlock = function(blockhash, cb) {
|
||||
Block.fromHashWithInfo(blockhash, function(err, block) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return cb(err);
|
||||
}
|
||||
return cb(err, block.info);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* List of blocks by date
|
||||
*/
|
||||
|
@ -89,13 +100,20 @@ exports.list = function(req, res) {
|
|||
if (err) {
|
||||
res.status(500).send(err);
|
||||
} else {
|
||||
res.jsonp({
|
||||
blocks: blocks,
|
||||
pagination: {
|
||||
next: next,
|
||||
prev: prev,
|
||||
current: dateStr
|
||||
}
|
||||
var blockshash = [];
|
||||
for(var i=0;i<blocks.length;i++) {
|
||||
blockshash.push(blocks[i].hash);
|
||||
}
|
||||
async.mapSeries(blockshash, getBlock, function(err, allblocks) {
|
||||
res.jsonp({
|
||||
blocks: allblocks,
|
||||
length: allblocks.length,
|
||||
pagination: {
|
||||
next: next,
|
||||
prev: prev,
|
||||
current: dateStr
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -51,6 +51,7 @@ var getTransaction = function(txid, cb) {
|
|||
* List of transaction
|
||||
*/
|
||||
exports.list = function(req, res, next) {
|
||||
var limit = req.query.limit || 5;
|
||||
var bId = req.query.block;
|
||||
var addrStr = req.query.address;
|
||||
var page = req.query.pageNum;
|
||||
|
@ -117,5 +118,28 @@ exports.list = function(req, res, next) {
|
|||
});
|
||||
});
|
||||
}
|
||||
else {
|
||||
Transaction
|
||||
.find()
|
||||
.limit(limit)
|
||||
.sort('-time')
|
||||
.exec(function(err, txs) {
|
||||
if (err) {
|
||||
res.status(500).send(err);
|
||||
} else {
|
||||
var txids = [];
|
||||
for(var i=0;i<txs.length;i++) {
|
||||
txids.push(txs[i].txid);
|
||||
}
|
||||
|
||||
async.mapSeries(txids, getTransaction, function(err, alltxs) {
|
||||
res.jsonp({
|
||||
txs: alltxs,
|
||||
length: alltxs.length
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -40,10 +40,10 @@ angular.module('insight.system').controller('IndexController',
|
|||
$scope.blocks = res.blocks;
|
||||
});
|
||||
|
||||
Transactions.query({
|
||||
Transactions.get({
|
||||
limit: TRANSACTION_DISPLAYED
|
||||
}, function(txs) {
|
||||
$scope.txs = txs;
|
||||
}, function(res) {
|
||||
$scope.txs = res.txs;
|
||||
});
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue