aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2020-10-19 08:48:22 -0400
committerAdam Soltys <[email protected]>2020-10-19 08:48:23 -0400
commitae9e9e0fa9cffd2545aa210321b34ce2bb5c4b8b (patch)
tree913ef3de1cbd7d450d31dc813b66bee5c7c849b7
parentf69540985a8735432f083253001b32933ad52409 (diff)
downloadcoinos-server-ae9e9e0fa9cffd2545aa210321b34ce2bb5c4b8b.tar.gz
coinos-server-ae9e9e0fa9cffd2545aa210321b34ce2bb5c4b8b.zip
check for negative swap amounts
-rw-r--r--routes/swaps.js15
1 files changed, 1 insertions, 14 deletions
diff --git a/routes/swaps.js b/routes/swaps.js
index a75be910..10beb0b2 100644
--- a/routes/swaps.js
+++ b/routes/swaps.js
@@ -121,6 +121,7 @@ app.post(
);
const swap = async (user, { a1, a2, v1, v2 }) => {
+ if (!parseInt(v1) || v1 < 0 || !parseInt(v2) || v2 < 0) throw new Error("Invalid amount");
let rate = v2 / v1;
const b = await lq.getBalance();
@@ -491,7 +492,6 @@ app.post(
const leg1 = info.legs.find(leg => !leg.incoming);
const leg2 = info.legs.find(leg => leg.incoming);
- console.log(info, rate, leg2.amount / leg1.amount);
let orders = await db.Order.findAll({
where: {
rate: { [Op.lte]: leg2.amount / leg1.amount },
@@ -524,8 +524,6 @@ app.post(
]
});
- console.log(orders.map(p => ({ rate: p.rate, v1: p.v1, a1: p.a1 })));
-
let total = orders.reduce((a, b) => a + b.v1, 0);
let remaining = Math.round(leg1.amount * SATS);
if (total < remaining)
@@ -540,11 +538,8 @@ app.post(
transaction
);
- console.log("aid", account.id);
-
let { v1: amount } = order;
if (remaining >= amount) {
- console.log(remaining);
remaining -= amount;
await db.Invoice.create({
@@ -592,14 +587,6 @@ app.post(
addresses[u_address_p] = order.user.username;
- console.log(
- "new math",
- order.v2,
- Math.round((order.v2 * remaining) / amount),
- amount,
- remaining,
- order.v1 - remaining
- );
order.decrement(
{
v1: remaining,