txId bug fixes; debugging
This commit is contained in:
parent
572bd7a10f
commit
3d9c95ba7f
4 changed files with 20 additions and 11 deletions
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
|
|
@ -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({
|
||||
.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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue