aboutsummaryrefslogtreecommitdiffstats
path: root/routes/lightning
diff options
context:
space:
mode:
authorAdrien Hopkins <[email protected]>2022-06-16 10:52:56 -0500
committerAdrien Hopkins <[email protected]>2022-06-16 10:52:56 -0500
commit55d4763146916e7e168bdc0ffd6d97c0d82f8e83 (patch)
treeb2d81dd41421fd4678d94465b79388d3f9fb67e0 /routes/lightning
parent8361c2d400145a13d9ba24299ceb7293e69d3d43 (diff)
downloadcoinos-server-55d4763146916e7e168bdc0ffd6d97c0d82f8e83.tar.gz
coinos-server-55d4763146916e7e168bdc0ffd6d97c0d82f8e83.zip
Added Lightning conversion fees (currently 0%)
Diffstat (limited to 'routes/lightning')
-rw-r--r--routes/lightning/conversionFee.js12
-rw-r--r--routes/lightning/receive.js4
2 files changed, 16 insertions, 0 deletions
diff --git a/routes/lightning/conversionFee.js b/routes/lightning/conversionFee.js
new file mode 100644
index 00000000..8fca9b0f
--- /dev/null
+++ b/routes/lightning/conversionFee.js
@@ -0,0 +1,12 @@
+// Code for the conversion fee
+// This is in a separate file so that the same function can be used by ./send and ./receive
+
+const conversionFeeMultiplier = 0.00;
+const conversionFeeReceiver = "coinosfees"; // account that receives the fees
+
+/**
+ * Returns the fee you have to pay for withdrawing 'amount' lightning BTC.
+ */
+function computeConversionFee(amount) {
+ return Math.floor(amount * conversionFeeMultiplier);
+}
diff --git a/routes/lightning/receive.js b/routes/lightning/receive.js
index 6723d577..6d10eb9b 100644
--- a/routes/lightning/receive.js
+++ b/routes/lightning/receive.js
@@ -1,3 +1,5 @@
+const { computeConversionFee } = require('./conversionFee.js');
+
const handlePayment = async (msg) => {
l.info("incoming lightning payment", msg.value, msg.payment_request, msg.settled);
if (!msg.settled) return;
@@ -60,6 +62,8 @@ const handlePayment = async (msg) => {
invoice.received += total;
await account.increment({ balance: total }, { transaction });
+ // get the # of fee credits you would need to pay off this amount of bitcoin
+ await account.increment({ btc_credits: computeConversionFee(total) }, { transaction });
await account.reload({ transaction });
await invoice.save({ transaction });
await payment.save({ transaction });