aboutsummaryrefslogtreecommitdiffstats
path: root/lib/send.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2022-09-22 02:57:54 +0000
committerAdam Soltys <[email protected]>2022-09-22 02:57:54 +0000
commit3f18d0c8ab508553062bf92a17295961f91a4822 (patch)
tree4608fc9f51820cdd48abc6352ddaf83f0e1208e3 /lib/send.js
parent45ae80bcde258622108c6d66e404660b0c037eb8 (diff)
parent918813a6e49f9d05828f6fb205614f9d288269e1 (diff)
downloadcoinos-server-3f18d0c8ab508553062bf92a17295961f91a4822.tar.gz
coinos-server-3f18d0c8ab508553062bf92a17295961f91a4822.zip
Merge remote-tracking branch 'origin/master' into prod2
Diffstat (limited to 'lib/send.js')
-rw-r--r--lib/send.js18
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/send.js b/lib/send.js
index 77d954f6..f20185e5 100644
--- a/lib/send.js
+++ b/lib/send.js
@@ -9,6 +9,7 @@ import {
conversionFeeReceiver
} from "../routes/lightning/conversionFee";
import lnd from "$lib/lnd";
+import ln from "$lib/ln";
import { payViaPaymentRequest } from "lightning";
import { l, warn, err } from "$lib/logging";
@@ -89,7 +90,9 @@ export default async (amount, memo, hash, user) => {
let tokens;
if (!payreq.satoshis) tokens = amount;
- let m = await payViaPaymentRequest({
+ let m;
+ if (config.lna.lnd) {
+ m = await payViaPaymentRequest({
lnd,
request: hash,
max_fee: Math.min(10000, account.balance)
@@ -97,8 +100,19 @@ export default async (amount, memo, hash, user) => {
if (!m) throw new Error(`lightning payment failed ${amount} ${hash}`);
if (m.payment_error) throw new Error(m.payment_error);
-
({ fee, secret: preimage, tokens: total } = m);
+ } else {
+ m = await ln.pay(hash, tokens ? `${tokens}sats` : undefined);
+ let sent;
+ ({
+ msatoshi: total,
+ msatoshi_sent: sent,
+ payment_preimage: preimage
+ } = m);
+
+ fee = parseInt((sent - total) / 1000);
+ total = parseInt(total / 1000);
+ }
preimage = preimage.toString("hex");