diff --git a/lib/postgresql_interface.js b/lib/postgresql_interface.js index 8cbf7fda..28a6a123 100644 --- a/lib/postgresql_interface.js +++ b/lib/postgresql_interface.js @@ -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); }; diff --git a/lib/routes.js b/lib/routes.js index 57bbfff7..77c3ab3e 100644 --- a/lib/routes.js +++ b/lib/routes.js @@ -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; diff --git a/lib/trader.js b/lib/trader.js index 4350c2fb..a099dae0 100644 --- a/lib/trader.js +++ b/lib/trader.js @@ -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); });