paging added back. Going over max config limit will default to config limit and still support paging.
This commit is contained in:
parent
cae4a45572
commit
98164e4447
@ -4,8 +4,6 @@ const config = require('../../config');
|
||||
|
||||
const block = new Block();
|
||||
|
||||
const MAX_BLOCKS = config.api.max_blocks; // ~ 12 hours
|
||||
|
||||
let bestBlockHeight = 0;
|
||||
|
||||
// 1e9 limit = ~2M years from now
|
||||
@ -29,8 +27,7 @@ function byHeight(height, cb) {
|
||||
}
|
||||
|
||||
function getTopBlocks(cb) {
|
||||
return block.last(cb)
|
||||
.limit(MAX_BLOCKS);
|
||||
return block.last(cb);
|
||||
}
|
||||
|
||||
function getByHash(hash, cb) {
|
||||
|
||||
@ -3,11 +3,6 @@ const logger = require('../logger');
|
||||
const config = require('../../config');
|
||||
|
||||
const Txs = new Transactions();
|
||||
|
||||
// No optimization yet.
|
||||
// Will be replaced with a more sophisticated api soon
|
||||
|
||||
const MAX_TXS = config.api.max_txs;
|
||||
const MAX_PAGE_TXS = config.api.max_page_txs;
|
||||
|
||||
function getEmptyInputs(cb) {
|
||||
@ -15,8 +10,7 @@ function getEmptyInputs(cb) {
|
||||
}
|
||||
|
||||
function getTopTransactions(cb) {
|
||||
return Txs.last(cb)
|
||||
.limit(MAX_TXS);
|
||||
return Txs.last(cb);
|
||||
}
|
||||
|
||||
function getTxById(txid, cb) {
|
||||
@ -25,14 +19,13 @@ function getTxById(txid, cb) {
|
||||
|
||||
function getTxByBlock(blockHash, page, limit, cb) {
|
||||
return Txs.byBlockHash(blockHash, cb)
|
||||
.limit(MAX_PAGE_TXS)
|
||||
.skip(MAX_PAGE_TXS * page);
|
||||
.skip(limit * page);
|
||||
}
|
||||
|
||||
function getTxByAddress(address, page, limit, cb) {
|
||||
return Txs.byAddress(address, cb)
|
||||
.limit(MAX_PAGE_TXS)
|
||||
.skip(MAX_PAGE_TXS * page);
|
||||
.limit(limit)
|
||||
.skip(limit * page);
|
||||
}
|
||||
|
||||
function getTxCountByBlock(blockHash, cb) {
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
const mongoose = require('mongoose');
|
||||
const Transaction = require('./transaction');
|
||||
const config = require('../config');
|
||||
|
||||
const Schema = mongoose.Schema;
|
||||
const MAX_BLOCKS = config.api.max_blocks; // ~ 12 hours
|
||||
|
||||
const BlockSchema = new Schema({
|
||||
hash: { type: String, default: '' },
|
||||
@ -48,10 +49,11 @@ BlockSchema.methods.getRawBlock = function getRawBlock(hash, cb) {
|
||||
cb);
|
||||
};
|
||||
|
||||
BlockSchema.methods.last = function lastTx(cb) {
|
||||
BlockSchema.methods.last = function lastBlocks(cb) {
|
||||
return this.model('Block').find(
|
||||
{},
|
||||
cb)
|
||||
.limit(MAX_BLOCKS)
|
||||
.sort({ height: -1 });
|
||||
};
|
||||
|
||||
|
||||
@ -2,8 +2,11 @@ const mongoose = require('mongoose');
|
||||
const Input = require('./input');
|
||||
const Output = require('./output');
|
||||
const logger = require('../lib/logger');
|
||||
const config = require('../config');
|
||||
|
||||
const Schema = mongoose.Schema;
|
||||
const MAX_TXS = config.api.max_txs;
|
||||
const MAX_PAGE_TXS = config.api.max_page_txs;
|
||||
|
||||
const TransactionSchema = new Schema({
|
||||
hash: { type: String, default: '' },
|
||||
@ -38,8 +41,8 @@ TransactionSchema.methods.byHash = function txByHash(hash, cb) {
|
||||
TransactionSchema.methods.byBlockHash = function txByBlockHash(hash, cb) {
|
||||
return this.model('Transaction').find(
|
||||
{ block: hash },
|
||||
cb,
|
||||
);
|
||||
cb)
|
||||
.limit(MAX_PAGE_TXS);
|
||||
};
|
||||
|
||||
TransactionSchema.methods.byAddress = function txByAddress(address, cb) {
|
||||
@ -49,15 +52,13 @@ TransactionSchema.methods.byAddress = function txByAddress(address, cb) {
|
||||
{ 'inputs.address': address },
|
||||
{ 'outputs.address': address }],
|
||||
},
|
||||
cb,
|
||||
);
|
||||
cb);
|
||||
};
|
||||
|
||||
TransactionSchema.methods.countByBlock = function txByAddress(hash, cb) {
|
||||
return this.model('Transaction').count(
|
||||
{ block: hash },
|
||||
cb,
|
||||
);
|
||||
cb);
|
||||
};
|
||||
|
||||
TransactionSchema.methods.countByAddress = function txByAddress(address, cb) {
|
||||
@ -67,15 +68,14 @@ TransactionSchema.methods.countByAddress = function txByAddress(address, cb) {
|
||||
{ 'inputs.address': address },
|
||||
{ 'outputs.address': address }],
|
||||
},
|
||||
cb,
|
||||
);
|
||||
cb);
|
||||
};
|
||||
|
||||
TransactionSchema.methods.last = function lastTx(cb) {
|
||||
return this.model('Transaction').find(
|
||||
{},
|
||||
cb,
|
||||
)
|
||||
cb)
|
||||
.limit(MAX_TXS)
|
||||
.sort({ height: -1 });
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user