bill reporting WIP

This commit is contained in:
Josh Harvey 2014-06-23 08:34:43 -04:00
parent 8c50444e80
commit 3ed2a96263
3 changed files with 21 additions and 8 deletions

View file

@ -24,18 +24,18 @@ PostgresqlInterface.prototype.recordBill =
function recordBill(deviceFingerprint, rec, cb) {
this.client.query('INSERT INTO bills (device_fingerprint, denomination, currency_code, ' +
'transaction_id) ' +
'VALUES ($1, $2, $3, $4)',
[deviceFingerprint, rec.fiat, rec.currency, rec.txId],
'satoshis, to_address, transaction_id, device_time) ' +
'VALUES ($1, $2, $3, $4, $5, $6, $7)',
[deviceFingerprint, rec.fiat, rec.currency, rec.satoshis, rec.toAddress, rec.txId, rec.deviceTime],
cb);
};
PostgresqlInterface.prototype.recordBillValidatorEvent =
PostgresqlInterface.prototype.recordDeviceEvent =
function recordBillValidatorEvent(deviceFingerprint, event, cb) {
this.client.query('INSERT INTO bill_validator_events (device_fingerprint, event_type, note)' +
'VALUES ($1, $2, $3)',
[deviceFingerprint, event.eventType, event.note],
this.client.query('INSERT INTO device_events (device_fingerprint, event_type, note, device_time)' +
'VALUES ($1, $2, $3, $4)',
[deviceFingerprint, event.eventType, event.note, event.deviceTime],
cb);
};

View file

@ -60,6 +60,12 @@ var trade = function (req, res) {
res.json({err: null});
};
var event = function (req, res) {
var fingerprint = req.connection.getPeerCertificate().fingerprint;
_trader.event(req.body, fingerprint);
res.json({err: null});
};
var send = function(req, res) {
var fingerprint = req.connection.getPeerCertificate().fingerprint;
_trader.sendBitcoins(fingerprint, req.body, function(err, txHash) {
@ -96,6 +102,7 @@ exports.init = function(app, config, trader, authMiddleware) {
app.get('/poll', authMiddleware, poll);
app.post('/send', authMiddleware, send);
app.post('/trade', authMiddleware, trade);
app.post('/event', authMiddleware, event);
app.post('/pair', pair);
return app;

View file

@ -195,8 +195,14 @@ Trader.prototype.sendBitcoins = function (deviceFingerprint, tx, cb) {
});
};
Trader.prototype.event = function (rec, deviceFingerprint) {
this.db.recordDeviceEvent(deviceFingerprint, rec, function (err) {
if (err) logger.error(err);
});
};
Trader.prototype.trade = function (rec, deviceFingerprint) {
self.db.recordBill(deviceFingerprint, rec, function (err) {
this.db.recordBill(deviceFingerprint, rec, function (err) {
if (err) logger.error(err);
});