/
orders.js
37 lines (33 loc) · 1.15 KB
/
orders.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'use strict';
const _ = require('lodash');
const utils = require('./utils');
const validate = utils.common.validate;
const composeAsync = utils.common.composeAsync;
const parseAccountOrder = require('./parse/account-order');
function requestAccountOffers(remote, address, ledgerVersion, options,
marker, limit, callback) {
remote.requestAccountOffers({
account: address,
marker: marker,
limit: limit,
ledger: ledgerVersion
},
composeAsync((data) => ({
marker: data.marker,
results: data.offers.map(parseAccountOrder)
}), callback));
}
function getAccountOrders(account, options, callback) {
validate.address(account);
validate.options(options);
const defaultLimit = 100;
const limit = options.limit || defaultLimit;
const ledgerVersion = options.ledgerVersion
|| this.remote.getLedgerSequence();
const getter = _.partial(requestAccountOffers, this.remote, account,
ledgerVersion, options);
utils.getRecursive(getter, limit,
composeAsync((orders) => _.sortBy(orders, (order) => order.state.sequence),
callback));
}
module.exports = getAccountOrders;