aboutsummaryrefslogtreecommitdiffstats
path: root/lib/send.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/send.js')
-rw-r--r--lib/send.js45
1 files changed, 25 insertions, 20 deletions
diff --git a/lib/send.js b/lib/send.js
index b61c0939..f8c53854 100644
--- a/lib/send.js
+++ b/lib/send.js
@@ -1,7 +1,11 @@
import store from "./store";
-import bolt11 from 'bolt11';
-import { Op } from '@sequelize/core';
-import { computeConversionFee, conversionFeeReceiver } from '../routes/lightning/conversionFee';
+import bolt11 from "bolt11";
+import { Op } from "@sequelize/core";
+import {
+ computeConversionFee,
+ conversionFeeReceiver
+} from "../routes/lightning/conversionFee";
+import ln from "$lib/ln";
export const send = async (amount, memo, hash, user) => {
l("attempting lightning payment", user.username, amount, hash);
@@ -55,13 +59,18 @@ export const send = async (amount, memo, hash, user) => {
transaction
});
- conversionFeeDeduction = Math.min(
- account.lightning_credits,
- conversionFee
- );
+ conversionFeeDeduction = Math.min(account.lightning_credits, conversionFee);
- if (!account || account.balance < amount + conversionFee - conversionFeeDeduction) {
- warn("user attempting to send more than they have", user.id, amount, conversionFee);
+ if (
+ !account ||
+ account.balance < amount + conversionFee - conversionFeeDeduction
+ ) {
+ warn(
+ "user attempting to send more than they have",
+ user.id,
+ amount,
+ conversionFee
+ );
throw new Error("Insufficient funds");
}
@@ -74,7 +83,7 @@ export const send = async (amount, memo, hash, user) => {
l("debited account", account.id);
if (config.lna.clightning) {
- let m = await lna.pay(hash);
+ let m = await ln.pay(hash);
let sent;
({
msatoshi: total,
@@ -85,20 +94,17 @@ export const send = async (amount, memo, hash, user) => {
fee = parseInt((sent - total) / 1000);
total = parseInt(total / 1000);
} else {
- let m = await lnp.sendPaymentSync({
- amt: amount,
- payment_request: hash,
- max_parts: 10,
- fee_limit: { fixed: Math.min(10000, account.balance) }
+ let m = await ln.pay({
+ tokens: amount,
+ request: hash,
+ max_paths: 10,
+ max_fee: { fixed: Math.min(10000, account.balance) }
});
if (!m) throw new Error(`lightning payment failed ${amount} ${hash}`);
if (m.payment_error) throw new Error(m.payment_error);
- ({
- payment_route: { total_fees: fee, total_amt: total },
- payment_preimage: preimage
- } = m);
+ ({ fee, secret: preimage, tokens: total } = m);
}
preimage = preimage.toString("hex");
@@ -206,7 +212,6 @@ export const send = async (amount, memo, hash, user) => {
l("created payment record", payment.id);
-
payment = payment.get({ plain: true });
payment.account = account.get({ plain: true });
payment.fee_payment = fee_payment && fee_payment.get({ plain: true });