add additional checks to /v1/blocks

This commit is contained in:
Manuel Araoz 2015-04-29 12:24:47 -03:00
parent 8ae8b0abf4
commit 630492b67a

View File

@ -68,12 +68,31 @@ Blocks.list = function(req, res) {
var offset = parseInt(req.query.offset || 0);
var limit = parseInt(req.query.limit || 10);
if (from < 0) {
res.status(422);
res.send('/v1/blocks/ "from" must be valid block height (a positive integer)');
return;
}
if (to < 0) {
res.status(422);
res.send('/v1/blocks/ "to" must be valid block height (a positive integer)');
return;
}
if (offset < 0) {
res.status(422);
res.send('/v1/blocks/ "offset" must be a positive integer');
return;
}
if (limit < 0) {
res.status(422);
res.send('/v1/blocks/ "limit" must be a positive integer');
return;
}
if (to < from) {
res.status(422);
res.send('/v1/blocks/ "to" must be >= "from"');
return;
}
// TODO: add more parameter validation
// TODO: return block_summary instead of block_full
node.blockService.listBlocks(from, to, offset, limit)