aboutsummaryrefslogtreecommitdiffstats
path: root/lib/payments.ts
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-10-16 15:33:22 -0700
committerAdam Soltys <[email protected]>2024-10-16 15:33:22 -0700
commite0ea06df4572c5183c5a4fd1697ca59c2614672c (patch)
treebd42b8194aa3485964beaef5ec2f8708e506503a /lib/payments.ts
parent4501538630af9d6026fe5661da0386d1b5d65008 (diff)
downloadcoinos-server-e0ea06df4572c5183c5a4fd1697ca59c2614672c.tar.gz
coinos-server-e0ea06df4572c5183c5a4fd1697ca59c2614672c.zip
atomic payment reversal
Diffstat (limited to 'lib/payments.ts')
-rw-r--r--lib/payments.ts18
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/payments.ts b/lib/payments.ts
index a073bec7..1f1497ec 100644
--- a/lib/payments.ts
+++ b/lib/payments.ts
@@ -809,14 +809,18 @@ let finalize = async (r, p) => {
};
let reverse = async (p) => {
- await db.del(`payment:${p.hash}`);
- await db.del(`payment:${p.id}`);
-
- let total = Math.abs(p.amount);
+ let total = Math.abs(p.amount) + p.fee;
let ourfee = p.ourfee || 0;
let credit = Math.round(total * config.fee) - ourfee;
- await db.incrBy(`balance:${p.uid}`, total + p.fee + ourfee);
- await db.incrBy(`credit:${types.lightning}:${p.uid}`, credit);
- await db.lRem(`${p.uid}:payments`, 1, p.id);
+ let k = await db.reverse(
+ `payment:${p.id}`,
+ `balance:${p.uid}`,
+ `credit:${types.lightning}:${p.uid}`,
+ `payment:${p.hash}`,
+ total,
+ credit,
+ );
+
+ warn("reversed", k);
};