aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdrien Hopkins <[email protected]>2022-06-16 12:23:23 -0500
committerAdrien Hopkins <[email protected]>2022-06-16 12:23:23 -0500
commit51ed4347d0dfcaac16957abf31848e0dd9d86b40 (patch)
treecad6b3e196562a170967c0c566f5512c7bbb7753
parent55d4763146916e7e168bdc0ffd6d97c0d82f8e83 (diff)
downloadcoinos-server-51ed4347d0dfcaac16957abf31848e0dd9d86b40.tar.gz
coinos-server-51ed4347d0dfcaac16957abf31848e0dd9d86b40.zip
Whether you can pay takes into account fee deductions
-rw-r--r--routes/bitcoin/send.js16
-rw-r--r--routes/liquid/send.js16
-rw-r--r--routes/lnurl.js13
3 files changed, 22 insertions, 23 deletions
diff --git a/routes/bitcoin/send.js b/routes/bitcoin/send.js
index 884c0db1..634b223b 100644
--- a/routes/bitcoin/send.js
+++ b/routes/bitcoin/send.js
@@ -58,14 +58,6 @@ module.exports = ah(async (req, res) => {
});
}
- if (total > account.balance) {
- l.error("amount exceeds balance", amount, fee, account.balance);
- throw new Error("low balance");
- } else if (total + conversionFee > account.balance) {
- l.error("total (after conversion fee) exceeds balance", amount, fee, account.balance);
- throw new Error("low balance (after conversion fee)");
- }
-
// use user's credits to reduce fee, if available
let conversionFeeDeduction = Math.min(account.btc_credits, conversionFee);
if (conversionFeeDeduction) {
@@ -74,6 +66,14 @@ module.exports = ah(async (req, res) => {
conversionFee -= conversionFeeDeduction;
}
+ if (total > account.balance) {
+ l.error("amount exceeds balance", amount, fee, account.balance);
+ throw new Error("low balance");
+ } else if (total + conversionFee > account.balance) {
+ l.error("total (after conversion fee) exceeds balance", amount, fee, account.balance);
+ throw new Error("low balance (after conversion fee)");
+ }
+
await account.decrement({ balance: (total + conversionFee) }, { transaction });
await account.reload({ transaction });
diff --git a/routes/liquid/send.js b/routes/liquid/send.js
index 5cda8ba5..254972ad 100644
--- a/routes/liquid/send.js
+++ b/routes/liquid/send.js
@@ -105,6 +105,14 @@ sendLiquid = async ({ asset, amount, user, address, memo, tx, limit }) => {
transaction
});
+ // use user's credits to reduce fee, if available
+ let conversionFeeDeduction = Math.min(account.liquid_credits, conversionFee);
+ if (conversionFeeDeduction) {
+ await account.decrement({ liquid_credits: conversionFeeDeduction }, { transaction });
+ await account.reload({ transaction });
+ conversionFee -= conversionFeeDeduction;
+ }
+
if (total > account.balance) {
l.warn("amount exceeds balance", {
total,
@@ -130,14 +138,6 @@ sendLiquid = async ({ asset, amount, user, address, memo, tx, limit }) => {
);
}
- // use user's credits to reduce fee, if available
- let conversionFeeDeduction = Math.min(account.liquid_credits, conversionFee);
- if (conversionFeeDeduction) {
- await account.decrement({ liquid_credits: conversionFeeDeduction }, { transaction });
- await account.reload({ transaction });
- conversionFee -= conversionFeeDeduction;
- }
-
await account.decrement({ balance: (total + conversionFee)}, { transaction });
await account.reload({ transaction });
diff --git a/routes/lnurl.js b/routes/lnurl.js
index 49212330..93d939f9 100644
--- a/routes/lnurl.js
+++ b/routes/lnurl.js
@@ -420,13 +420,6 @@ lnurlServer.bindToHook(
transaction
});
- if (account.balance < amount) {
- throw new Error("Insufficient funds");
- } else if (account.balance < amount + conversionFee) {
- throw new Error("Insufficient funds for conversion fee");
- }
-
- // use user's credits to reduce fee, if available
let conversionFeeDeduction = Math.min(account.lightning_credits, conversionFee);
if (conversionFeeDeduction) {
await account.decrement({ lightning_credits: conversionFeeDeduction }, { transaction });
@@ -434,6 +427,12 @@ lnurlServer.bindToHook(
conversionFee -= conversionFeeDeduction;
}
+ if (account.balance < amount) {
+ throw new Error("Insufficient funds");
+ } else if (account.balance < amount + conversionFee) {
+ throw new Error("Insufficient funds for conversion fee");
+ }
+
let fee_payment_id = null;
if (conversionFee) {
await receiverAccount.increment({ balance: conversionFee }, { transaction });