Merge pull request #1 from tj-bitpay/new_branch
first alteration and find
This commit is contained in:
commit
434b077467
@ -1,13 +1,42 @@
|
||||
const Transaction = require('../../models/transaction.js').Transaction;
|
||||
|
||||
var MAX_TXS = 200;
|
||||
|
||||
function getTransaction(params, options, cb) {
|
||||
const defaultOptions = { _id: 0 };
|
||||
|
||||
Object.assign(defaultOptions, options);
|
||||
|
||||
Transaction.find(
|
||||
params,
|
||||
defaultOptions,
|
||||
cb)
|
||||
.sort({ height: -1 })
|
||||
.limit(MAX_TXS);
|
||||
}
|
||||
|
||||
module.exports = function transactionAPI(app) {
|
||||
app.get('/tx/:txid', (req, res) => {
|
||||
res.send(req.params.txid);
|
||||
Transaction.find({"txid":req.params.txid}, (err, tx) => {
|
||||
if (err) {
|
||||
res.status(501).send();
|
||||
}
|
||||
res.send(tx);
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/txs', (req, res) => {
|
||||
res.send('list of txs');
|
||||
|
||||
getTransaction(
|
||||
{},
|
||||
{},
|
||||
(err, txs) => {
|
||||
if (err) {
|
||||
res.status(501).send();
|
||||
}
|
||||
console.log(txs.length);
|
||||
res.send(txs);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
app.get('/rawtx/:txid', (req, res) => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user