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.
|
* Module dependencies.
|
||||||
*/
|
*/
|
||||||
var mongoose = require('mongoose'),
|
var mongoose = require('mongoose'),
|
||||||
Block = mongoose.model('Block'),
|
Block = mongoose.model('Block'),
|
||||||
common = require('./common');
|
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
|
* List of blocks by date
|
||||||
*/
|
*/
|
||||||
@ -89,13 +100,20 @@ exports.list = function(req, res) {
|
|||||||
if (err) {
|
if (err) {
|
||||||
res.status(500).send(err);
|
res.status(500).send(err);
|
||||||
} else {
|
} else {
|
||||||
res.jsonp({
|
var blockshash = [];
|
||||||
blocks: blocks,
|
for(var i=0;i<blocks.length;i++) {
|
||||||
pagination: {
|
blockshash.push(blocks[i].hash);
|
||||||
next: next,
|
}
|
||||||
prev: prev,
|
async.mapSeries(blockshash, getBlock, function(err, allblocks) {
|
||||||
current: dateStr
|
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
|
* List of transaction
|
||||||
*/
|
*/
|
||||||
exports.list = function(req, res, next) {
|
exports.list = function(req, res, next) {
|
||||||
|
var limit = req.query.limit || 5;
|
||||||
var bId = req.query.block;
|
var bId = req.query.block;
|
||||||
var addrStr = req.query.address;
|
var addrStr = req.query.address;
|
||||||
var page = req.query.pageNum;
|
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;
|
$scope.blocks = res.blocks;
|
||||||
});
|
});
|
||||||
|
|
||||||
Transactions.query({
|
Transactions.get({
|
||||||
limit: TRANSACTION_DISPLAYED
|
limit: TRANSACTION_DISPLAYED
|
||||||
}, function(txs) {
|
}, function(res) {
|
||||||
$scope.txs = txs;
|
$scope.txs = res.txs;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user