Merge pull request #1 from tj-bitpay/new_branch

first alteration and find
This commit is contained in:
Alex 2017-08-04 17:02:39 -04:00 committed by GitHub
commit 434b077467

View File

@ -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) => {