From 8c50444e80cf318b3d23a0ce5d39a700986349c8 Mon Sep 17 00:00:00 2001 From: Josh Harvey Date: Sat, 21 Jun 2014 14:13:12 -0400 Subject: [PATCH] bill-reporting WIP --- lib/postgresql_interface.js | 19 +++++++++++++++++++ lib/trader.js | 6 +++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/postgresql_interface.js b/lib/postgresql_interface.js index 2b7885eb..8cbf7fda 100644 --- a/lib/postgresql_interface.js +++ b/lib/postgresql_interface.js @@ -20,6 +20,25 @@ var PostgresqlInterface = function (conString) { PostgresqlInterface.factory = function factory(conString) { return new PostgresqlInterface(conString); }; module.exports = PostgresqlInterface; +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], + cb); +}; + +PostgresqlInterface.prototype.recordBillValidatorEvent = + 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], + cb); +}; + PostgresqlInterface.prototype.summonTransaction = function summonTransaction(deviceFingerprint, tx, cb) { // First do an INSERT diff --git a/lib/trader.js b/lib/trader.js index ee181f71..4350c2fb 100644 --- a/lib/trader.js +++ b/lib/trader.js @@ -196,6 +196,10 @@ Trader.prototype.sendBitcoins = function (deviceFingerprint, tx, cb) { }; Trader.prototype.trade = function (rec, deviceFingerprint) { + self.db.recordBill(deviceFingerprint, rec, function (err) { + if (err) logger.error(err); + }); + // This is where we record starting trade balance at the beginning // of the user session var sessionInfo = this._sessionInfo[deviceFingerprint]; @@ -336,7 +340,7 @@ Trader.prototype.pollRate = function (callback) { logger.debug('got rates: %j', resRates); self.rateInfo = {rates: resRates, timestamp: new Date()}; - callback && callback(); + if (callback) callback(); }); };