aboutsummaryrefslogtreecommitdiffstats
path: root/lib/send.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/send.js')
-rw-r--r--lib/send.js15
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/send.js b/lib/send.js
index 5997b379..f717d8f8 100644
--- a/lib/send.js
+++ b/lib/send.js
@@ -29,6 +29,7 @@ export default async (amount, memo, hash, user) => {
}
if (!amount || payreq.satoshis > amount) amount = payreq.satoshis;
+ amount = parseInt(amount);
if (store.seen.includes(hash)) {
warn("attempted to pay a paid invoice", user.username);
@@ -67,6 +68,7 @@ export default async (amount, memo, hash, user) => {
conversionFeeDeduction = Math.min(account.lightning_credits, conversionFee);
total = amount + conversionFee - conversionFeeDeduction;
+ console.log("a t lc cf cfd", amount, total, account.lightning_credits, conversionFee, conversionFeeDeduction);
if (!account || account.balance < total) {
warn(
@@ -98,7 +100,7 @@ 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, tokens: total } = m);
+ ({ fee, secret, tokens } = m);
preimage = secret.toString("hex");
} else {
let { msatoshi, msatoshi_sent, payment_preimage } = await ln.pay(
@@ -107,7 +109,6 @@ export default async (amount, memo, hash, user) => {
);
preimage = payment_preimage;
fee = parseInt((msatoshi_sent - msatoshi) / 1000);
- total = parseInt(msatoshi / 1000);
}
if (store.seen.includes(preimage)) {
@@ -146,9 +147,7 @@ export default async (amount, memo, hash, user) => {
transaction
});
- total = parseInt(total);
- fee = parseInt(fee);
-
+ l("deducting fee", fee);
await account.decrement({ balance: fee }, { transaction });
await account.reload({ transaction });
@@ -156,6 +155,8 @@ export default async (amount, memo, hash, user) => {
conversionFee -= conversionFeeDeduction;
}
+ l("conversion fee", conversionFee);
+
let receiverAccount = await db.Account.findOne({
where: {
"$user.username$": conversionFeeReceiver
@@ -198,7 +199,7 @@ export default async (amount, memo, hash, user) => {
payment = await db.Payment.create(
{
- amount: -(total - fee),
+ amount: -total,
account_id: account.id,
user_id: user.id,
hash,
@@ -223,7 +224,7 @@ export default async (amount, memo, hash, user) => {
emit(user.username, "account", payment.account);
emit(user.username, "payment", payment);
- l("sent lightning", user.username, total - fee, fee);
+ l("sent lightning", user.username, amount, total, fee);
});
return payment;