Bisq: Feature to filter transaction types.

This commit is contained in:
softsimon
2020-07-24 18:41:15 +07:00
parent 24182a6fb3
commit 7f71781916
8 changed files with 166 additions and 46 deletions

View File

@@ -39,8 +39,12 @@ class Bisq {
return this.transactionIndex[txId];
}
getTransactions(start: number, length: number): [BisqTransaction[], number] {
return [this.transactions.slice(start, length + start), this.transactions.length];
getTransactions(start: number, length: number, types: string[]): [BisqTransaction[], number] {
let transactions = this.transactions;
if (types.length) {
transactions = transactions.filter((tx) => types.indexOf(tx.txType) > -1);
}
return [transactions.slice(start, length + start), transactions.length];
}
getBlock(hash: string): BisqBlock | undefined {

View File

@@ -108,9 +108,21 @@ class Routes {
}
public getBisqTransactions(req: Request, res: Response) {
const types: string[] = [];
if (req.query.types && !Array.isArray(req.query.types)) {
res.status(500).send('Types is not an array');
return;
} else {
for (const _type in req.query.types) {
if (typeof req.query.types[_type] === 'string') {
types.push(req.query.types[_type].toString());
}
}
}
const index = parseInt(req.params.index, 10) || 0;
const length = parseInt(req.params.length, 10) > 100 ? 100 : parseInt(req.params.length, 10) || 25;
const [transactions, count] = bisq.getTransactions(index, length);
const [transactions, count] = bisq.getTransactions(index, length, types);
res.header('X-Total-Count', count.toString());
res.json(transactions);
}