mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-22 05:05:48 +00:00
Merge notifications functionality into getAccountTransactions
This commit is contained in:
@@ -6,6 +6,7 @@ const utils = require('./utils');
|
||||
const parseTransaction = require('./parse/transaction');
|
||||
const validate = utils.common.validate;
|
||||
const errors = utils.common.errors;
|
||||
const composeAsync = utils.common.composeAsync;
|
||||
|
||||
const DEFAULT_LIMIT = 100;
|
||||
const MIN_LEDGER_VERSION = 32570; // earlier versions have been completely lost
|
||||
@@ -81,7 +82,6 @@ function parseAccountTxTransaction(tx) {
|
||||
return parseTransaction(tx.tx);
|
||||
}
|
||||
|
||||
|
||||
function transactionFilter(address, filters, tx) {
|
||||
if (filters.excludeFailures && tx.outcome.result !== 'tesSUCCESS') {
|
||||
return false;
|
||||
@@ -98,14 +98,20 @@ function transactionFilter(address, filters, tx) {
|
||||
return true;
|
||||
}
|
||||
|
||||
function orderFilter(options, tx) {
|
||||
return !options.startTx || (options.earliestFirst ?
|
||||
utils.compareTransactions(tx, options.startTx) > 0 :
|
||||
utils.compareTransactions(tx, options.startTx) < 0);
|
||||
}
|
||||
|
||||
function getAccountTx(remote, address, options, marker, limit, callback) {
|
||||
const params = {
|
||||
account: address,
|
||||
ledger_index_min: options.ledgerVersion || options.minLedgerVersion || -1,
|
||||
ledger_index_max: options.ledgerVersion || options.maxLedgerVersion || -1,
|
||||
ledger_index_min: options.minLedgerVersion || -1,
|
||||
ledger_index_max: options.maxLedgerVersion || -1,
|
||||
forward: options.earliestFirst,
|
||||
binary: options.binary,
|
||||
limit: Math.min(limit || DEFAULT_LIMIT, 10),
|
||||
limit: Math.max(limit || DEFAULT_LIMIT, 10),
|
||||
marker: marker
|
||||
};
|
||||
|
||||
@@ -116,20 +122,40 @@ function getAccountTx(remote, address, options, marker, limit, callback) {
|
||||
.filter((tx) => tx.validated)
|
||||
.map(parseAccountTxTransaction)
|
||||
.filter(_.partial(transactionFilter, address, options))
|
||||
.filter(_.partial(orderFilter, options))
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getAccountTransactions(address, options, callback) {
|
||||
validate.address(address);
|
||||
|
||||
function getAccountTransactionsInternal(remote, address, options, callback) {
|
||||
const limit = options.limit || DEFAULT_LIMIT;
|
||||
const compare = options.earliestFirst ? utils.compareTransactions :
|
||||
_.rearg(utils.compareTransactions, 1, 0);
|
||||
const getter = _.partial(getAccountTx, this.remote, address, options);
|
||||
utils.getRecursive(getter, limit, (error, data) => {
|
||||
return error ? callback(error) : callback(null, data.sort(compare));
|
||||
});
|
||||
const getter = _.partial(getAccountTx, remote, address, options);
|
||||
utils.getRecursive(getter, limit,
|
||||
composeAsync((txs) => txs.sort(compare), callback));
|
||||
}
|
||||
|
||||
function getAccountTransactions(address, options, callback) {
|
||||
validate.address(address);
|
||||
validate.getAccountTransactionsOptions(options);
|
||||
|
||||
const remote = this.remote;
|
||||
if (options.start) {
|
||||
getTransaction.bind(this)(options.start, {}, (error, tx) => {
|
||||
if (error) {
|
||||
callback(error);
|
||||
return;
|
||||
}
|
||||
const ledgerVersion = tx.outcome.ledgerVersion;
|
||||
const ledgerOption = options.earliestFirst ?
|
||||
{minLedgerVersion: ledgerVersion} : {maxLedgerVersion: ledgerVersion};
|
||||
const newOptions = _.assign({}, options, {startTx: tx}, ledgerOption);
|
||||
getAccountTransactionsInternal(remote, address, newOptions, callback);
|
||||
});
|
||||
} else {
|
||||
getAccountTransactionsInternal(remote, address, options, callback);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
Reference in New Issue
Block a user