From 92ffc6e2e597867a55b592a20b16c233efad9cef Mon Sep 17 00:00:00 2001 From: Gyulai Zoltan Date: Tue, 12 Oct 2021 13:53:33 +0300 Subject: feat: added lightning withdrawal with hardcoded fee estimation --- lib/send.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'lib') 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"); -- cgit v1.2.3