diff options
| author | Adam Soltys <[email protected]> | 2022-09-20 22:48:01 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2022-09-20 22:48:01 -0700 |
| commit | b53875cf6bdf47c359139aa846c6597fa3627c87 (patch) | |
| tree | d4e7c71c5be97903a43e0e25f816b2a4b9fde0a5 /lib/send.js | |
| parent | 2b552fdd6eca883ee24d2772e1de24f4bab70202 (diff) | |
| download | coinos-server-b53875cf6bdf47c359139aa846c6597fa3627c87.tar.gz coinos-server-b53875cf6bdf47c359139aa846c6597fa3627c87.zip | |
clightning support
Diffstat (limited to 'lib/send.js')
| -rw-r--r-- | lib/send.js | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/send.js b/lib/send.js index 77d954f6..9d70b34e 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.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"); |
