From d1cc66d1a02b75f90fbf0c05910777c76228259a Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 2 Sep 2022 15:06:43 -0700 Subject: es6 migration --- lib/send.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'lib/send.js') diff --git a/lib/send.js b/lib/send.js index e589ca6b..15855d55 100644 --- a/lib/send.js +++ b/lib/send.js @@ -1,9 +1,10 @@ +import { rates } from "./store.js"; import bolt11 from 'bolt11'; import { Op } from '@sequelize/core'; import { computeConversionFee, conversionFeeReceiver } from '../routes/lightning/conversionFee.js'; export const send = async (amount, memo, hash, user) => { - l.info("attempting lightning payment", user.username, amount, hash); + l("attempting lightning payment", user.username, amount, hash); let payreq = bolt11.decode(hash); let routingInfo = payreq.tags.find(t => t.tagName === "routing_info"); @@ -11,7 +12,7 @@ export const send = async (amount, memo, hash, user) => { routingInfo && routingInfo.data.find(d => d.fee_proportional_millionths > 10000) ) { - l.warn("fee rate too high", d.fee_proportional_millionths); + warn("fee rate too high", d.fee_proportional_millionths); throw new Error( "Couldn't find a suitable route to pay to your destination" ); @@ -20,7 +21,7 @@ export const send = async (amount, memo, hash, user) => { if (!amount || payreq.satoshis > amount) amount = payreq.satoshis; if (seen.includes(hash)) { - l.warn("attempted to pay a paid invoice", user.username); + warn("attempted to pay a paid invoice", user.username); throw new Error("Invoice has been paid, can't pay again"); } @@ -29,7 +30,7 @@ export const send = async (amount, memo, hash, user) => { let conversionFee = computeConversionFee(amount); let conversionFeeDeduction; await db.transaction(async transaction => { - l.info("starting lightning send transaction"); + l("starting lightning send transaction"); let account; if (user.account.asset === config.liquid.btcasset) account = await db.Account.findOne({ @@ -60,7 +61,7 @@ export const send = async (amount, memo, hash, user) => { ); if (!account || account.balance < amount + conversionFee - conversionFeeDeduction) { - l.warn("user attempting to send more than they have", user.id, amount, conversionFee); + warn("user attempting to send more than they have", user.id, amount, conversionFee); throw new Error("Insufficient funds"); } @@ -70,7 +71,7 @@ export const send = async (amount, memo, hash, user) => { ); await account.reload({ transaction }); - l.info("debited account", account.id); + l("debited account", account.id); if (config.lna.clightning) { let m = await lna.pay(hash); @@ -103,13 +104,13 @@ export const send = async (amount, memo, hash, user) => { preimage = preimage.toString("hex"); if (seen.includes(preimage)) { - l.warn("duplicate payment detected", preimage); + warn("duplicate payment detected", preimage); throw new Error("Duplicate payment detected"); } }); await db.transaction(async transaction => { - l.info("starting lightning fee transaction"); + l("starting lightning fee transaction"); let account; if (user.account.asset === config.liquid.btcasset) @@ -174,7 +175,7 @@ export const send = async (amount, memo, hash, user) => { memo: "Lightning conversion fee", account_id: receiverAccount.id, user_id: receiverAccount.user_id, - rate: app.get("rates")[receiverAccount.user.currency], + rate: rates[receiverAccount.user.currency], currency: receiverAccount.user.currency, confirmed: true, received: true, @@ -193,7 +194,7 @@ export const send = async (amount, memo, hash, user) => { hash, memo, preimage, - rate: app.get("rates")[user.currency], + rate: rates[user.currency], currency: user.currency, confirmed: true, network: "lightning", @@ -203,7 +204,7 @@ export const send = async (amount, memo, hash, user) => { { transaction } ); - l.info("created payment record", payment.id); + l("created payment record", payment.id); payment = payment.get({ plain: true }); @@ -216,7 +217,7 @@ export const send = async (amount, memo, hash, user) => { seen.push(preimage); seen.push(hash); - l.info("sent lightning", user.username, total - fee, fee); + l("sent lightning", user.username, total - fee, fee); }); return payment; -- cgit v1.2.3