need new mongo models from another branch
This commit is contained in:
parent
898e373b77
commit
d2f68fefe9
@ -28,7 +28,8 @@ const config = {
|
||||
ticker_url: 'https://www.bitstamp.net/api/ticker/',
|
||||
ticker_prop: 'bitstamp',
|
||||
max_blocks: 72,
|
||||
max_txs: 10,
|
||||
max_txs: 50,
|
||||
max_page_txs: 10,
|
||||
request_ttl: 100000,
|
||||
},
|
||||
};
|
||||
|
||||
@ -86,7 +86,7 @@ module.exports = function transactionAPI(router) {
|
||||
return res.status(400).send({
|
||||
error: 'Invalid block hash',
|
||||
});
|
||||
}
|
||||
}
|
||||
const height = db.blocks.bestHeight();
|
||||
// Get Bcoin data
|
||||
return request(`${API_URL}/block/${req.query.block}`,
|
||||
@ -204,7 +204,17 @@ module.exports = function transactionAPI(router) {
|
||||
});
|
||||
}
|
||||
// Get last n txs
|
||||
return res.status(404).send({ error: 'Block hash or address expected' });
|
||||
console.log('GETTING N TXS');
|
||||
db.txs.getTopTransactions((err, txs) => {
|
||||
if (err) {
|
||||
logger.log('err',
|
||||
`/txs getTopTransactions ${err}`);
|
||||
return res.status(404).send(err);
|
||||
}
|
||||
return res.json(txs);
|
||||
});
|
||||
|
||||
// return res.status(404).send({ error: 'Block hash or address expected' });
|
||||
});
|
||||
|
||||
router.get('/rawtx/:txid', (req, res) => {
|
||||
|
||||
@ -4,9 +4,12 @@ const config = require('../../config');
|
||||
|
||||
// For now, blocks handles these calls.
|
||||
// These will be replaced with more advanced mongo
|
||||
// No optimization yet.
|
||||
|
||||
const MAX_TXS = config.api.max_txs;
|
||||
const MAX_TXS = config.api.max_page_txs;
|
||||
const MAX_PAGE_TXS = config.api.max_page_txs;
|
||||
|
||||
// For Paging
|
||||
function getTransactions(params, options, limit, cb) {
|
||||
// Do not return mongo ids
|
||||
const defaultOptions = { _id: 0 };
|
||||
@ -17,8 +20,8 @@ function getTransactions(params, options, limit, cb) {
|
||||
limit = 1;
|
||||
}
|
||||
|
||||
if (limit > MAX_TXS) {
|
||||
limit = MAX_TXS;
|
||||
if (limit > MAX_PAGE_TXS) {
|
||||
limit = MAX_PAGE_TXS;
|
||||
}
|
||||
|
||||
if (limit < 1) {
|
||||
@ -57,7 +60,30 @@ function getTransaction(params, options, limit, cb) {
|
||||
});
|
||||
}
|
||||
|
||||
// Req Change, refactor above
|
||||
function getTopTransactions(cb) {
|
||||
// Do not return mongo ids
|
||||
const defaultOptions = { _id: 0 };
|
||||
// Query mongo
|
||||
Transactions.find(
|
||||
{},
|
||||
(err, txs) => {
|
||||
if (err) {
|
||||
logger.log('error',
|
||||
`getTransactions: ${err}`);
|
||||
return cb(err);
|
||||
}
|
||||
if (!txs.length > 0) {
|
||||
return cb({ err: 'Tx not found' });
|
||||
}
|
||||
return cb(null, txs);
|
||||
})
|
||||
.sort({ height: -1 })
|
||||
.limit(MAX_TXS);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getTransaction,
|
||||
getTransactions,
|
||||
getTopTransactions,
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user