WIP cleaned up migrations
This commit is contained in:
parent
78f8d08d7d
commit
fe008a9db6
4 changed files with 57 additions and 57 deletions
|
|
@ -190,10 +190,10 @@ function removePendingTx(client, sessionId, cb) {
|
|||
function insertOutgoingTx(client, deviceFingerprint, tx, totals, cb) {
|
||||
var sendAmount = computeSendAmount(tx, totals);
|
||||
var stage = 'partial_request';
|
||||
var source = tx.fiat ? 'machine' : 'timeout';
|
||||
var authority = tx.fiat ? 'machine' : 'timeout';
|
||||
var satoshis = sendAmount.satoshis;
|
||||
var fiat = sendAmount.fiat;
|
||||
insertTx(client, deviceFingerprint, tx, satoshis, fiat, stage, source,
|
||||
insertTx(client, deviceFingerprint, tx, satoshis, fiat, stage, authority,
|
||||
function(err) {
|
||||
|
||||
if (err) return cb(err);
|
||||
|
|
@ -207,18 +207,18 @@ function insertOutgoingCompleteTx(client, deviceFingerprint, tx, cb) {
|
|||
if (!tx.fiat) return cb();
|
||||
|
||||
var stage = 'final_request';
|
||||
var source = 'machine';
|
||||
var authority = 'machine';
|
||||
var satoshis = tx.satoshis;
|
||||
var fiat = tx.fiat;
|
||||
insertTx(client, deviceFingerprint, tx, satoshis, fiat, stage, source, cb);
|
||||
insertTx(client, deviceFingerprint, tx, satoshis, fiat, stage, authority, cb);
|
||||
}
|
||||
|
||||
function insertTx(client, deviceFingerprint, tx, satoshis, fiat, stage,
|
||||
source, cb) {
|
||||
authority, cb) {
|
||||
var fields = [
|
||||
'session_id',
|
||||
'stage',
|
||||
'source',
|
||||
'authority',
|
||||
'incoming',
|
||||
'device_fingerprint',
|
||||
'to_address',
|
||||
|
|
@ -232,7 +232,7 @@ function insertTx(client, deviceFingerprint, tx, satoshis, fiat, stage,
|
|||
var values = [
|
||||
tx.txId,
|
||||
stage,
|
||||
source,
|
||||
authority,
|
||||
tx.incoming,
|
||||
deviceFingerprint,
|
||||
tx.toAddress,
|
||||
|
|
@ -308,19 +308,19 @@ exports.sentCoins = function sentCoins(tx, satoshis, fee, error, txHash) {
|
|||
});
|
||||
};
|
||||
|
||||
exports.addIncomingTx = function addIncomingTx(deviceFingerprint, tx, source,
|
||||
exports.addIncomingTx = function addIncomingTx(deviceFingerprint, tx, authority,
|
||||
satoshisReceived, cb) {
|
||||
connect(function(err, client, done) {
|
||||
function maybeRemovePending(client, sessionId, source, cb) {
|
||||
if (source === 'published') return cb();
|
||||
function maybeRemovePending(client, sessionId, authority, cb) {
|
||||
if (authority === 'published') return cb();
|
||||
removePendingTx(client, sessionId, cb);
|
||||
}
|
||||
|
||||
if (err) return cb(err);
|
||||
async.waterfall([
|
||||
async.apply(silentQuery, client, 'BEGIN', null),
|
||||
async.apply(maybeRemovePending, client, tx.sessionId, source),
|
||||
async.apply(insertTx, client, tx, satoshisReceived, 0, 'deposit', source)
|
||||
async.apply(maybeRemovePending, client, tx.sessionId, authority),
|
||||
async.apply(insertTx, client, tx, satoshisReceived, 0, 'deposit', authority)
|
||||
], function(err) {
|
||||
if (err) {
|
||||
rollback(client, done);
|
||||
|
|
@ -358,7 +358,7 @@ exports.addInitialIncoming = function addInitialIncoming(deviceFingerprint, tx,
|
|||
};
|
||||
|
||||
function lastTxStatus(client, deviceFingerprint, sessionId, cb) {
|
||||
var sql = 'SELECT satoshis, source FROM transactions ' +
|
||||
var sql = 'SELECT satoshis, authority FROM transactions ' +
|
||||
'WHERE device_fingerprint=$1 AND session_id=$2 AND incoming=$3 ' +
|
||||
'ORDER BY id DESC LIMIT 1';
|
||||
var values = [deviceFingerprint, sessionId, true];
|
||||
|
|
@ -400,7 +400,7 @@ exports.dispenseStatus = function dispenseStatus(deviceFingerprint, sessionId,
|
|||
// TODO: handle multiple deposits
|
||||
var status = (lastTx.satoshis < requiredSatoshis) ?
|
||||
'insufficientFunds' :
|
||||
lastTx.source;
|
||||
lastTx.authority;
|
||||
cb(null, status);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue