aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorGyulai Zoltan <[email protected]>2021-10-12 13:53:33 +0300
committerGyulai Zoltan <[email protected]>2021-10-12 13:53:33 +0300
commit92ffc6e2e597867a55b592a20b16c233efad9cef (patch)
tree9bfad78872592637a241624de9edde36986b4b07 /lib
parent5f949a00ab98792db22bb5ab0104a06c714932f2 (diff)
downloadcoinos-server-withdraw.tar.gz
coinos-server-withdraw.zip
feat: added lightning withdrawal with hardcoded fee estimationwithdraw
Diffstat (limited to 'lib')
-rw-r--r--lib/send.js10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/send.js b/lib/send.js
index 293473d9..8edd1e58 100644
--- a/lib/send.js
+++ b/lib/send.js
@@ -1,7 +1,9 @@
const bolt11 = require("bolt11");
const { Op } = require("sequelize");
-send = async (amount, memo, hash, user) => {
+const ESTIMATED_FEE = 1000;
+
+send = async (amount, memo, hash, user, subtractFee = false) => {
let payreq = bolt11.decode(hash);
let routingInfo = payreq.tags.find(t => t.tagName === "routing_info");
if (
@@ -12,6 +14,12 @@ send = async (amount, memo, hash, user) => {
if (!amount || payreq.satoshis > amount) amount = payreq.satoshis;
+ if(subtractFee) {
+ amount -= ESTIMATED_FEE;
+ if(amount < 0)
+ throw new Error('Subtracted fee is greater than amount to send')
+ }
+
if (seen.includes(hash)) {
l.warn("attempted to pay a paid invoice", user.username);
throw new Error("Invoice has been paid, can't pay again");