bill reporting WIP
This commit is contained in:
parent
8c50444e80
commit
3ed2a96263
3 changed files with 21 additions and 8 deletions
|
|
@ -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);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue