diff --git a/bin/lamassu-server b/bin/lamassu-server index 3f928db3..72621dbc 100755 --- a/bin/lamassu-server +++ b/bin/lamassu-server @@ -4,7 +4,7 @@ var fs = require('fs') var options = require('../lib/options') -process.env.LAMASSU_ENV = process.env.LAMASSU_ENV || options.logLevel +process.env.LAMASSU_ENV = process.env.LAMASSU_ENV || options.logLevel || 'info' var createServer = require('../lib/app.js') var argv = require('minimist')(process.argv.slice(2)) diff --git a/lib/plugins.js b/lib/plugins.js index b32c8051..ef303bce 100644 --- a/lib/plugins.js +++ b/lib/plugins.js @@ -276,6 +276,7 @@ exports.pollQueries = function pollQueries (deviceId) { function _sendCoins (toAddress, cryptoAtoms, cryptoCode) { return new Promise((resolve, reject) => { _sendCoinsCb(toAddress, cryptoAtoms, cryptoCode, (err, txHash) => { + console.log('DEBUG12: %j, %j', err, txHash) if (err) return reject(err) return resolve(txHash) }) @@ -297,9 +298,12 @@ function _sendCoinsCb (toAddress, cryptoAtoms, cryptoCode, cb) { // NOTE: This will fail if we have already sent coins because there will be // a db unique db record in the table already. function executeTx (deviceId, tx) { + console.log('DEBUG16: %j', tx) return db.addOutgoingTx(deviceId, tx) .then(() => _sendCoins(tx.toAddress, tx.cryptoAtoms, tx.cryptoCode)) .then(txHash => { + console.log('DEBUG13: %j', txHash) + const fee = null // Need to fill this out in plugins const toSend = {cryptoAtoms: tx.cryptoAtoms, fiat: tx.fiat} @@ -308,7 +312,7 @@ function executeTx (deviceId, tx) { .then(() => ({ statusCode: 201, // Created txHash, - txId: tx.txId + txId: tx.id })) }) } @@ -355,8 +359,8 @@ exports.recordPing = function recordPing (deviceId, deviceTime, rec, cb) { return db.machineEvent(event) } -exports.sendCoins = function sendCoins (rawTx) { - return executeTx(rawTx) +exports.sendCoins = function sendCoins (deviceId, rawTx) { + return executeTx(deviceId, rawTx) } exports.cashOut = function cashOut (deviceId, tx) { diff --git a/lib/postgresql_interface.js b/lib/postgresql_interface.js index 922abb8f..77f984c7 100644 --- a/lib/postgresql_interface.js +++ b/lib/postgresql_interface.js @@ -42,6 +42,7 @@ exports.init = function init (conString) { // logs inputted bill and overall tx status (if available) exports.recordBill = function recordBill (deviceId, rec) { + console.log('DEBUG10: %j', rec) const fields = [ 'id', 'device_id', @@ -66,6 +67,8 @@ exports.recordBill = function recordBill (deviceId, rec) { rec.fiat ] + console.log('DEBUG11: %j', values) + return db.none(getInsertQuery('bills', fields), values) .catch(err => { if (isUniqueViolation(err)) return logger.warn('Attempt to report bill twice') diff --git a/lib/routes.js b/lib/routes.js index 80b2676c..3566a3da 100644 --- a/lib/routes.js +++ b/lib/routes.js @@ -133,15 +133,17 @@ function send (req, res) { const tx = req.body tx.cryptoAtoms = new BigNumber(tx.cryptoAtoms) - // TODO: use status.statusCode here after confirming machine compatibility - // FIX: (joshm) set txHash to status.txId instead of previous status.txHash which wasn't being set - // Need to clean up txHash vs txId return plugins.sendCoins(getDeviceId(req), tx) - .then(status => res.json({ - txHash: status && status.txHash, - txId: status && status.txId - })) + .then(status => { + console.log('DEBUG14: %j', status) + + res.json({ + txHash: status && status.txHash, + txId: status && status.txId + }) + }) .catch(err => { + console.log('DEBUG15: %s', err) logger.error(err) res.json({ err: err.message,