major refactoring to use session object
This commit is contained in:
parent
fe008a9db6
commit
0b438a62e5
4 changed files with 94 additions and 120 deletions
|
|
@ -182,8 +182,8 @@ exports.getCachedConfig = function getCachedConfig() {
|
|||
return cachedConfig;
|
||||
};
|
||||
|
||||
exports.logEvent = function event(rawEvent, deviceFingerprint) {
|
||||
db.recordDeviceEvent(deviceFingerprint, rawEvent);
|
||||
exports.logEvent = function event(session, rawEvent) {
|
||||
db.recordDeviceEvent(session, rawEvent);
|
||||
};
|
||||
|
||||
function _sendBitcoins(toAddress, satoshis, cb) {
|
||||
|
|
@ -191,8 +191,8 @@ function _sendBitcoins(toAddress, satoshis, cb) {
|
|||
walletPlugin.sendBitcoins(toAddress, satoshis, transactionFee, cb);
|
||||
}
|
||||
|
||||
function executeTx(deviceFingerprint, tx, cb) {
|
||||
db.addOutgoingTx(deviceFingerprint, tx, function(err, satoshisToSend) {
|
||||
function executeTx(session, tx, cb) {
|
||||
db.addOutgoingTx(session, tx, function(err, satoshisToSend) {
|
||||
if (err) return cb(err);
|
||||
|
||||
if (satoshisToSend === 0)
|
||||
|
|
@ -200,7 +200,7 @@ function executeTx(deviceFingerprint, tx, cb) {
|
|||
|
||||
_sendBitcoins(tx.toAddress, satoshisToSend, function(_err, txHash) {
|
||||
var fee = null; // Need to fill this out in plugins
|
||||
db.sentCoins(tx, satoshisToSend, fee, _err, txHash);
|
||||
db.sentCoins(session, tx, satoshisToSend, fee, _err, txHash);
|
||||
|
||||
if (_err) return cb(err);
|
||||
|
||||
|
|
@ -214,30 +214,29 @@ function executeTx(deviceFingerprint, tx, cb) {
|
|||
});
|
||||
}
|
||||
|
||||
function reapOutgoingTx(deviceFingerprint, tx) {
|
||||
executeTx(deviceFingerprint, tx, function(err) {
|
||||
function reapOutgoingTx(session, tx) {
|
||||
executeTx(session, tx, function(err) {
|
||||
if (err) logger.error(err);
|
||||
});
|
||||
}
|
||||
|
||||
function reapIncomingTx(deviceFingerprint, tx) {
|
||||
function reapIncomingTx(session, tx) {
|
||||
infoPlugin.checkAddress(tx.toAddress, function(err, status,
|
||||
satoshisReceived) {
|
||||
if (status === 'notSeen') return;
|
||||
db.addIncomingTx(deviceFingerprint, tx, status, satoshisReceived);
|
||||
db.addIncomingTx(session, tx, status, satoshisReceived);
|
||||
});
|
||||
}
|
||||
|
||||
function reapTx(row) {
|
||||
var deviceFingerprint = row.device_fingerprint;
|
||||
var session = {fingerprint: row.device_fingerprint, id: row.session_id};
|
||||
var tx = {
|
||||
txId: row.txid,
|
||||
toAddress: row.to_address,
|
||||
currencyCode: row.currency_code,
|
||||
incoming: row.incoming
|
||||
};
|
||||
if (row.incoming) reapIncomingTx(deviceFingerprint, tx);
|
||||
else reapOutgoingTx(deviceFingerprint, tx);
|
||||
if (row.incoming) reapIncomingTx(session, tx);
|
||||
else reapOutgoingTx(session, tx);
|
||||
}
|
||||
|
||||
function reapTxs() {
|
||||
|
|
@ -257,7 +256,7 @@ function reapTxs() {
|
|||
}
|
||||
|
||||
// TODO: Run these in parallel and return success
|
||||
exports.trade = function trade(deviceFingerprint, rawTrade, cb) {
|
||||
exports.trade = function trade(session, rawTrade, cb) {
|
||||
|
||||
// TODO: move this to DB, too
|
||||
// add bill to trader queue (if trader is enabled)
|
||||
|
|
@ -277,16 +276,16 @@ exports.trade = function trade(deviceFingerprint, rawTrade, cb) {
|
|||
};
|
||||
|
||||
async.parallel([
|
||||
async.apply(db.addPendingTx, deviceFingerprint, tx),
|
||||
async.apply(db.recordBill, deviceFingerprint, rawTrade)
|
||||
async.apply(db.addPendingTx, session, tx),
|
||||
async.apply(db.recordBill, session, rawTrade)
|
||||
], cb);
|
||||
};
|
||||
|
||||
exports.sendBitcoins = function sendBitcoins(deviceFingerprint, rawTx, cb) {
|
||||
executeTx(deviceFingerprint, rawTx, cb);
|
||||
exports.sendBitcoins = function sendBitcoins(session, rawTx, cb) {
|
||||
executeTx(session, rawTx, cb);
|
||||
};
|
||||
|
||||
exports.cashOut = function cashOut(deviceFingerprint, tx, cb) {
|
||||
exports.cashOut = function cashOut(session, tx, cb) {
|
||||
var tmpInfo = {
|
||||
label: 'TX ' + Date.now(),
|
||||
account: 'deposit'
|
||||
|
|
@ -294,19 +293,18 @@ exports.cashOut = function cashOut(deviceFingerprint, tx, cb) {
|
|||
walletPlugin.newAddress(tmpInfo, function(err, address) {
|
||||
if (err) return cb(err);
|
||||
|
||||
db.addInitialIncoming(deviceFingerprint, tx, address, function(_err) {
|
||||
db.addInitialIncoming(session, tx, address, function(_err) {
|
||||
cb(_err, address);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
exports.dispenseStatus = function dispenseStatus(deviceFingerprint, sessionId,
|
||||
cb) {
|
||||
db.fetchDispenseStatus(deviceFingerprint, sessionId, cb);
|
||||
exports.dispenseStatus = function dispenseStatus(session, cb) {
|
||||
db.fetchDispenseStatus(session, cb);
|
||||
};
|
||||
|
||||
exports.dispenseAck = function dispenseAck(deviceFingerprint, tx) {
|
||||
db.addDispense(deviceFingerprint, tx);
|
||||
exports.dispenseAck = function dispenseAck(session, tx) {
|
||||
db.addDispense(session, tx);
|
||||
};
|
||||
|
||||
exports.fiatBalance = function fiatBalance() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue