Skip to content

Commit 01e6114

Browse files
committed
add paymentVolume API and metrics
1 parent 0db4e4a commit 01e6114

12 files changed

+753
-224
lines changed

api/app.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ var apiRoutes = {
8585
'offers' : require("./routes/offers"),
8686
//'offersexercised' : require("./routes/offersExercised"),
8787
'offersexercised' : require("./routesV2/exchanges"),
88+
'payments' : require("./routesV2/payments"),
89+
'totalpaymentvolume' : require("./routesV2/totalPaymentVolume"),
8890
'topmarkets' : require("./routes/totalTradeVolume"),
8991
'totaltradevolume' : require("./routes/totalTradeVolume"),
9092
'markettraders' : require("./routes/marketTraders"),
@@ -196,8 +198,11 @@ function requestHandler(req, res) {
196198
res.send(200, response);
197199

198200
//log the response
199-
if (response.length) rowcount = response.length;
200-
else if (response.results) rowcount = response.results.length;
201+
if (response && response.length) {
202+
rowcount = response.length;
203+
} else if (response && response.results) {
204+
rowcount = response.results.length;
205+
}
201206

202207
winston.info(date,
203208
ip,
@@ -295,9 +300,6 @@ function makeKey(route, params) {
295300
return cacheKey;
296301
}
297302

298-
//initialize ledger monitor
299-
monitor.ledgerMonitor();
300-
301303
//cache initialization
302304
if (CACHE) {
303305
if (!config.redis || !config.redis.port || !config.redis.host) {

api/library/hbase/hbase-client.js

+119-17
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,49 @@ function HbaseClient() {
4747
HbaseClient.prototype = Object.create(Hbase.prototype);
4848
HbaseClient.prototype.constructor = HbaseClient;
4949

50+
/**
51+
* getCapitalization
52+
*/
53+
54+
HbaseClient.prototype.getCapitalization = function (options, callback) {
55+
var base = options.currency + '|' + options.issuer;
56+
var startRow = base + '|' + utils.formatTime(options.start);
57+
var endRow = base + '|' + utils.formatTime(options.end);
58+
var column;
59+
60+
if (options.adjustedChanges) {
61+
column = 'hotwallet_adj_balancesowed';
62+
} else if (options.changes) {
63+
column = 'issuer_balance_changes';
64+
} else if (options.adjusted) {
65+
column = 'cummulative_hotwallet_adj_balancesowed';
66+
} else {
67+
column = 'cummulative_issuer_balance_changes';
68+
}
69+
70+
this.getScanWithMarker(this, {
71+
table: 'issuer_balance_snapshot',
72+
startRow: startRow,
73+
stopRow: endRow,
74+
limit: options.limit || Infinity,
75+
descending: options.descending,
76+
marker: options.marker,
77+
columns : ['d:'+column]
78+
}, function(err, resp) {
79+
if (resp && resp.rows) {
80+
resp.rows.forEach(function(row, i) {
81+
var parts = row.rowkey.split('|');
82+
resp.rows[i] = {
83+
date: utils.unformatTime(parts[2]).format(),
84+
amount: 0 - Number(row[column])
85+
};
86+
});
87+
88+
callback(err, resp);
89+
}
90+
});
91+
}
92+
5093
/**
5194
* getStats
5295
*/
@@ -192,26 +235,51 @@ HbaseClient.prototype.getStatsRow = function(options) {
192235
*/
193236

194237
HbaseClient.prototype.getPayments = function(options, callback) {
195-
var table = 'payments';
196-
var startRow = utils.formatTime(options.start);
197-
var endRow = utils.formatTime(options.end);
198238
var filters = [];
199239
var filterString;
240+
var table;
241+
var startRow;
242+
var endRow;
200243

201-
if (options.currency) {
202-
filters.push({
203-
qualifier: 'currency',
204-
value: options.currency,
205-
family: 'f', comparator: '='
206-
});
207-
}
244+
if (options.interval) {
245+
table = 'agg_payments';
246+
startRow = options.interval +
247+
'|' + options.currency +
248+
'|' + (options.issuer || '') +
249+
'|' + utils.formatTime(options.start);
250+
endRow = options.interval +
251+
'|' + options.currency +
252+
'|' + (options.issuer || '') +
253+
'|' + utils.formatTime(options.end);
208254

209-
if (options.issuer) {
210-
filters.push({
211-
qualifier: 'issuer',
212-
value: options.issuer,
213-
family: 'f', comparator: '='
214-
});
255+
} else {
256+
table = 'payments';
257+
startRow = utils.formatTime(options.start);
258+
endRow = utils.formatTime(options.end);
259+
260+
if (options.currency) {
261+
filters.push({
262+
qualifier: 'currency',
263+
value: options.currency,
264+
family: 'f', comparator: '='
265+
});
266+
}
267+
268+
if (options.issuer) {
269+
filters.push({
270+
qualifier: 'issuer',
271+
value: options.issuer,
272+
family: 'f', comparator: '='
273+
});
274+
}
275+
276+
if (options.reduce) {
277+
options.columns = [
278+
'd:delivered_amount',
279+
'f:currency',
280+
'f:issuer'
281+
];
282+
}
215283
}
216284

217285
filterString = this.buildSingleColumnValueFilters(filters);
@@ -226,7 +294,40 @@ HbaseClient.prototype.getPayments = function(options, callback) {
226294
filterString: filterString,
227295
columns: options.columns
228296
}, function(err, res) {
229-
res.rows = formatPayments(res.rows || []);
297+
var amount;
298+
299+
if (options.interval) {
300+
if (res && res.rows) {
301+
res.rows.forEach(function(row) {
302+
row.count = Number(row.count);
303+
row.amount = Number(row.amount);
304+
row.average = Number(row.average);
305+
});
306+
}
307+
308+
} else if (options.reduce) {
309+
amount = 0;
310+
311+
if (res && res.rows) {
312+
res.rows.forEach(function(row) {
313+
amount += Number(row.delivered_amount);
314+
});
315+
316+
res = {
317+
amount: amount,
318+
count: res.rows.length
319+
};
320+
321+
} else {
322+
res = {
323+
amount: 0,
324+
count: 0
325+
};
326+
}
327+
328+
} else {
329+
res.rows = formatPayments(res.rows || []);
330+
}
230331
callback(err, res);
231332
});
232333

@@ -474,6 +575,7 @@ HbaseClient.prototype.getAccountBalanceChanges = function (options, callback) {
474575
stopRow : endRow,
475576
limit : options.limit,
476577
marker : options.marker,
578+
descending : options.descending,
477579
filterString : filterString
478580
}, function (err, res) {
479581
res.rows= formatChanges(res.rows || []);

api/library/history.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ function saveHistory (metric, interval, update, done) {
1818
check = require("../routes/totalTradeVolume");
1919
load = require("./metrics/tradeVolume");
2020

21-
} else if (metric === 'transactionVolume') {
22-
check = require("../routes/totalValueSent");
23-
load = require("./metrics/transactionVolume");
21+
} else if (metric === 'paymentVolume') {
22+
check = require("../routesV2/totalPaymentVolume");
23+
load = require("./metrics/paymentVolume");
2424

2525
} else if (metric === 'networkValue') {
2626
check = require("../routes/totalNetworkValue");
2727
load = require("./metrics/networkValue");
2828

29-
} else return winston.error("invalid metric");
29+
} else return winston.error("invalid metric: " + metric);
3030

3131
if (interval != 'month' &&
3232
interval != 'week' &&
@@ -101,7 +101,7 @@ module.exports.init = function(reload) {
101101

102102
var saveMonthlyHistory = function (update, done) {
103103
saveHistory('tradeVolume', "month", update, function() {
104-
saveHistory('transactionVolume', "month", update, function() {
104+
saveHistory('paymentVolume', "month", update, function() {
105105
saveHistory('networkValue', "month", update, function() {
106106
winston.info("finished cacheing monthly historical metrics");
107107
if(done) done();
@@ -112,7 +112,7 @@ module.exports.init = function(reload) {
112112

113113
var saveWeeklyHistory = function (update, done) {
114114
saveHistory('tradeVolume', "week", update, function() {
115-
saveHistory('transactionVolume', "week", update, function() {
115+
saveHistory('paymentVolume', "week", update, function() {
116116
saveHistory('networkValue', "week", update, function() {
117117
winston.info("finished cacheing daily historical metrics");
118118
if (done) done();
@@ -123,7 +123,7 @@ module.exports.init = function(reload) {
123123

124124
var saveDailyHistory = function (update, done) {
125125
saveHistory('tradeVolume', "day", update, function() {
126-
saveHistory('transactionVolume', "day", update, function() {
126+
saveHistory('paymentVolume', "day", update, function() {
127127
saveHistory('networkValue', "day", update, function() {
128128
winston.info("finished cacheing daily historical metrics");
129129
if (done) done();

api/library/metrics/index.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
var async = require('async');
2-
var cacheTradeVolume = require('./tradeVolume');
3-
var cacheTransactionVolume = require('./transactionVolume');
4-
var cacheNetworkValue = require('./networkValue');
1+
var async = require('async');
2+
var cacheTradeVolume = require('./tradeVolume');
3+
var cachePaymentVolume = require('./paymentVolume');
4+
var cacheNetworkValue = require('./networkValue');
55

66
module.exports.init = function () {
77

@@ -14,8 +14,8 @@ module.exports.init = function () {
1414

1515
function cacheMetrics () {
1616
async.series([
17-
function (callback) {cacheTradeVolume(null, callback)},
18-
function (callback) {cacheTransactionVolume(null, callback)},
19-
function (callback) {cacheNetworkValue(null, callback)},
17+
//function (callback) {cacheTradeVolume(null, callback)},
18+
function (callback) {cachePaymentVolume(null, callback)},
19+
//function (callback) {cacheNetworkValue(null, callback)},
2020
]);
2121
}

0 commit comments

Comments
 (0)