Skip to content

Commit

Permalink
FIX: better stuck payments handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Overtorment committed Apr 13, 2019
1 parent 35d8ff5 commit 2c25a20
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion class/Lock.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class Lock {
}

// success - got lock
await this._redis.expire(this._lock_key, 3600);
await this._redis.expire(this._lock_key, 5 * 60);
// lock expires in 5 mins just for any case
return true;
}
Expand Down
6 changes: 3 additions & 3 deletions class/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ export class User {

let lockedPayments = await this.getLockedPayments();
for (let paym of lockedPayments) {
// TODO: check if payment in determined state and actually evict it from this list
calculatedBalance -= +paym.amount;
// locked payments are processed in scripts/process-locked-payments.js
calculatedBalance -= +paym.amount + /* feelimit */ Math.floor(paym.amount * 0.01);
}

return calculatedBalance;
Expand All @@ -173,7 +173,7 @@ export class User {
async saveBalance(balance) {
const key = 'balance_for_' + this._userid;
await this._redis.set(key, balance);
await this._redis.expire(key, 3600);
await this._redis.expire(key, 1800);
}

async clearBalanceCache() {
Expand Down
10 changes: 10 additions & 0 deletions controllers/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,16 @@ router.get('/gettxs', async function(req, res) {
try {
await u.accountForPosibleTxids();
let txs = await u.getTxs();
let lockedPayments = await u.getLockedPayments();
for (let locked of lockedPayments) {
txs.push({
type: 'paid_invoice',
fee: Math.floor(locked.amount * 0.01) /* feelimit */,
value: locked.amount + Math.floor(locked.amount * 0.01) /* feelimit */,
timestamp: locked.timestamp,
memo: 'Payment in transition',
});
}
res.send(txs);
} catch (Err) {
logger.log('', [req.id, 'error:', Err]);
Expand Down

0 comments on commit 2c25a20

Please sign in to comment.