WIP -- handle state change requests
This commit is contained in:
parent
2400504827
commit
7c15ce0ae8
3 changed files with 32 additions and 2 deletions
|
|
@ -121,7 +121,7 @@ function loadOrConfigPlugin(pluginHandle, pluginType, currency,
|
||||||
pluginHandle = loadPlugin(currentName, pluginConfig);
|
pluginHandle = loadPlugin(currentName, pluginConfig);
|
||||||
currentlyUsedPlugins[pluginType] = currentName
|
currentlyUsedPlugins[pluginType] = currentName
|
||||||
logger.debug('plugin(%s) loaded: %s', pluginType, pluginHandle.NAME ||
|
logger.debug('plugin(%s) loaded: %s', pluginType, pluginHandle.NAME ||
|
||||||
currentName);
|
currentName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -317,6 +317,17 @@ exports.trade = function trade(session, rawTrade, cb) {
|
||||||
], cb);
|
], cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.stateChange = function stateChange(session, rec, cb) {
|
||||||
|
var rec = {
|
||||||
|
id: rec.uuid,
|
||||||
|
fingerprint: session.fingerprint,
|
||||||
|
eventType: 'stateChange',
|
||||||
|
note: JSON.stringify({state: rec.state, sessionId: session.id}),
|
||||||
|
deviceTime: rec.deviceTime
|
||||||
|
}
|
||||||
|
db.machineEvent(rec, cb)
|
||||||
|
};
|
||||||
|
|
||||||
exports.sendBitcoins = function sendBitcoins(session, rawTx, cb) {
|
exports.sendBitcoins = function sendBitcoins(session, rawTx, cb) {
|
||||||
executeTx(session, rawTx, 'machine', cb);
|
executeTx(session, rawTx, 'machine', cb);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
/* @flow weak */
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// TODO: Consider using serializable transactions for true ACID
|
// TODO: Consider using serializable transactions for true ACID
|
||||||
|
|
@ -514,6 +513,19 @@ exports.cartridgeCounts = function cartridgeCounts(session, cb) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.machineEvent = function machineEvent(rec, cb) {
|
||||||
|
connect(function(cerr, client, done) {
|
||||||
|
if (cerr) return cb(cerr);
|
||||||
|
var sql = 'insert into machine_events (id, device_fingerprint, event_type, note, device_time) ' +
|
||||||
|
'VALUES (?, ?, ?, ?, ?)';
|
||||||
|
var values = [rec.id, rec.fingerprint, rec.eventType, rec.note, rec.deviceTime]
|
||||||
|
query(client, sql, values, function(err, results) {
|
||||||
|
done();
|
||||||
|
return cb(err, results);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
exports.init('postgres://lamassu:lamassu@localhost/lamassu');
|
exports.init('postgres://lamassu:lamassu@localhost/lamassu');
|
||||||
connect(function(err, client, done) {
|
connect(function(err, client, done) {
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,12 @@ function trade(req, res) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function stateChange(req, res) {
|
||||||
|
plugins.stateChange(session(req), req.body, function(err) {
|
||||||
|
res.json(200)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function send(req, res) {
|
function send(req, res) {
|
||||||
plugins.sendBitcoins(session(req), req.body, function(err, status) {
|
plugins.sendBitcoins(session(req), req.body, function(err, status) {
|
||||||
// TODO: use status.statusCode here after confirming machine compatibility
|
// TODO: use status.statusCode here after confirming machine compatibility
|
||||||
|
|
@ -189,6 +195,7 @@ function init(localConfig) {
|
||||||
app.get('/poll', authMiddleware, reloadConfigMiddleware, poll);
|
app.get('/poll', authMiddleware, reloadConfigMiddleware, poll);
|
||||||
|
|
||||||
app.post('/trade', authMiddleware, trade);
|
app.post('/trade', authMiddleware, trade);
|
||||||
|
app.post('/state', authMiddleware, stateChange);
|
||||||
app.post('/send', authMiddleware, send);
|
app.post('/send', authMiddleware, send);
|
||||||
|
|
||||||
app.post('/cash_out', authMiddleware, cashOut);
|
app.post('/cash_out', authMiddleware, cashOut);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue