fix insufficient deposit
This commit is contained in:
parent
209272eb26
commit
5c82d2ad95
3 changed files with 11 additions and 11 deletions
|
|
@ -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});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue