diff options
| author | Adam Soltys <[email protected]> | 2022-10-06 03:59:03 +0000 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2022-10-06 03:59:03 +0000 |
| commit | ea44c7ea627d4b4e56a9819b992c6fb6d24eaa1a (patch) | |
| tree | 6350ccbf6bdb2642cc9d04d3eac20f3d1f6d4c7e | |
| parent | 397e77d8fec8f7455919468a98a8292b2de78228 (diff) | |
| download | coinos-server-ea44c7ea627d4b4e56a9819b992c6fb6d24eaa1a.tar.gz coinos-server-ea44c7ea627d4b4e56a9819b992c6fb6d24eaa1a.zip | |
fix lightning totals
| -rw-r--r-- | lib/send.js | 15 |
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; |
