fix insufficient deposit
This commit is contained in:
parent
209272eb26
commit
5c82d2ad95
3 changed files with 11 additions and 11 deletions
|
|
@ -14,6 +14,7 @@ var PENDING_TIMEOUT = 70 * 1000;
|
|||
// TODO: might have to update this if user is allowed to extend monitoring time
|
||||
var DEPOSIT_TIMEOUT = 120 * 1000;
|
||||
|
||||
|
||||
var db = null;
|
||||
|
||||
var tickerPlugin = null;
|
||||
|
|
@ -426,7 +427,6 @@ function stopTrader() {
|
|||
}
|
||||
|
||||
function pollBalance(cb) {
|
||||
logger.debug('collecting balance');
|
||||
|
||||
var jobs = {
|
||||
transferBalance: walletPlugin.balance
|
||||
|
|
@ -444,7 +444,6 @@ function pollBalance(cb) {
|
|||
return cb && cb(err);
|
||||
}
|
||||
|
||||
logger.debug('Balance update:', balance);
|
||||
balance.timestamp = Date.now();
|
||||
lastBalances = balance;
|
||||
|
||||
|
|
@ -453,15 +452,12 @@ function pollBalance(cb) {
|
|||
}
|
||||
|
||||
function pollRate(cb) {
|
||||
logger.debug('polling for rates (%s)', tickerPlugin.NAME);
|
||||
|
||||
tickerPlugin.ticker(deviceCurrency, function(err, resRates) {
|
||||
if (err) {
|
||||
logger.error(err);
|
||||
return cb && cb(err);
|
||||
}
|
||||
|
||||
logger.debug('got rates: %j', resRates);
|
||||
resRates.timestamp = new Date();
|
||||
lastRates = resRates;
|
||||
|
||||
|
|
|
|||
|
|
@ -358,8 +358,11 @@ exports.sentCoins = function sentCoins(session, tx, authority, toSend, fee,
|
|||
});
|
||||
};
|
||||
|
||||
function maybeRemovePending(client, session, authority, cb) {
|
||||
if (authority === 'published') return cb();
|
||||
function maybeRemovePending(client, session, insufficientFunds, authority, cb) {
|
||||
|
||||
// Keep waiting for authorization, unless deposit is insufficient
|
||||
if (authority === 'published' && !insufficientFunds) return cb();
|
||||
|
||||
removePendingTx(client, session, cb);
|
||||
}
|
||||
|
||||
|
|
@ -368,9 +371,12 @@ exports.addIncomingTx = function addIncomingTx(session, tx, authority,
|
|||
|
||||
connect(function(cerr, client, done) {
|
||||
if (cerr) return cb(cerr);
|
||||
var satoshisRequested = tx.satoshis;
|
||||
var insufficientFunds = satoshisReceived < satoshisRequested;
|
||||
async.waterfall([
|
||||
async.apply(silentQuery, client, 'BEGIN', null),
|
||||
async.apply(maybeRemovePending, client, session, authority),
|
||||
async.apply(maybeRemovePending, client, session, insufficientFunds,
|
||||
authority),
|
||||
async.apply(insertIncoming, client, session, tx, satoshisReceived, 0,
|
||||
'deposit', authority)
|
||||
], function(err) {
|
||||
|
|
@ -456,11 +462,10 @@ exports.dispenseStatus = function dispenseStatus(session, cb) {
|
|||
if (!pending) return cb(null, null);
|
||||
|
||||
var requestedTx = results[0].rows[0];
|
||||
var requiredSatoshis = requestedTx.requiredSatoshis;
|
||||
var lastTx = results[1].rows[0];
|
||||
|
||||
// TODO: handle multiple deposits
|
||||
var status = (lastTx.satoshis < requiredSatoshis) ?
|
||||
var status = (lastTx.satoshis < requestedTx.satoshis) ?
|
||||
'insufficientFunds' :
|
||||
lastTx.authority;
|
||||
cb(null, {status: status, fiat: requestedTx.fiat});
|
||||
|
|
|
|||
|
|
@ -77,7 +77,6 @@ function poll(req, res) {
|
|||
function trade(req, res) {
|
||||
plugins.trade(session(req), req.body, function(err) {
|
||||
var statusCode = err ? 500 : 201;
|
||||
console.dir(err); // DEBUG
|
||||
res.json(statusCode, {err: err});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue