-
Notifications
You must be signed in to change notification settings - Fork 17
/
indexes.js
74 lines (64 loc) · 2 KB
/
indexes.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* indexes.js
*
* This file acts as a layer on top of markets.js to provide indexes and
* slightly processed versions of those market definitions.
*/
var _ = require('lodash');
var markets = require('./markets');
// Process issuers
exports.issuers = _.map(markets.issuers, function (issuer, i) {
return _.merge({id: i}, issuer);
});
// Index issuers
exports.issuersByAddress = {};
exports.issuersByIOU = {};
exports.issuersByName = {};
exports.issuerByCurrencyAddress = {};
exports.issuers.forEach(function (issuer, i) {
_.each(issuer.currencies, function (address, cur) {
exports.issuersByAddress[address] = issuer;
exports.issuersByIOU[cur + ':' + address] = issuer;
exports.issuerByCurrencyAddress[cur + ':' + address] = issuer;
});
exports.issuersByName[issuer.name] = issuer;
});
// -----------------------------------------------------------------------------
// Process currencies
exports.currencies = _.map(markets.currencies, function (currency, i) {
return {
id: i,
cur: currency
};
});
// Index currencies
exports.currenciesByCode = {};
exports.currencies.forEach(function (cur) {
exports.currenciesByCode[cur.cur] = cur;
});
// -----------------------------------------------------------------------------
exports.xrpHighlightedBySymbol = {};
_.each(markets.xrp, function (symbol, i) {
exports.xrpHighlightedBySymbol[symbol] = i;
});
// Process XRP markets
exports.xrp = [];
_.each(exports.issuers, function (issuer) {
_.each(issuer.currencies, function (address, currency) {
var symbol = currency + ":" + issuer.name;
exports.xrp.push({
sym: symbol,
first: currency + "/" + address,
second: "XRP",
cur: exports.currenciesByCode[currency],
iss: issuer,
// Is highlighted? (highlighted means featured on front page)
hl: "undefined" !== typeof exports.xrpHighlightedBySymbol[symbol]
});
});
});
// Index XRP markets
exports.xrpByCur = {};
exports.xrp.forEach(function (market) {
exports.xrpByCur[market.iou] = market;
});