diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/binance.js | 2 | ||||
| -rw-r--r-- | lib/passport.js | 8 | ||||
| -rw-r--r-- | lib/rates.js | 6 | ||||
| -rw-r--r-- | lib/send.js | 45 |
4 files changed, 31 insertions, 30 deletions
diff --git a/lib/binance.js b/lib/binance.js index 3c142a8f..af8d0b15 100644 --- a/lib/binance.js +++ b/lib/binance.js @@ -20,7 +20,7 @@ export default () => { // app.set("ask", msg.a); // app.set("bid", msg.b); - last = msg.c; + store.last = msg.c; } catch (e) { err("binance message error", e.message); } diff --git a/lib/passport.js b/lib/passport.js index 7cf07962..68adbe08 100644 --- a/lib/passport.js +++ b/lib/passport.js @@ -1,4 +1,5 @@ import app from "$app"; +import db from "$db"; import Passport from "passport"; import jwt from "passport-jwt"; import { Op } from "@sequelize/core"; @@ -7,6 +8,7 @@ import fastifySecureSession from '@fastify/secure-session' import config from "$config"; import fs from "fs"; import path from "path"; +import { err } from "$lib/logging"; app.register(fastifySecureSession, { key: config.jwt @@ -58,9 +60,8 @@ export const optionalAuth = { preValidation: fastifyPassport.authenticate( "jwt", { session: false }, - function(err, user, info) { + function(req, res, err, user, info) { req.user = user; - next(); } ) }; @@ -69,10 +70,9 @@ export const adminAuth = { preValidation: fastifyPassport.authenticate( "jwt", { session: false }, - function(err, user, info) { + function(req, res, err, user, info) { if (!(user && user.admin)) return res.status(401).send("Unauthorized"); req.user = user; - next(); } ) }; diff --git a/lib/rates.js b/lib/rates.js index 84152da3..5a8ba536 100644 --- a/lib/rates.js +++ b/lib/rates.js @@ -1,5 +1,6 @@ import app from "$app"; import axios from "axios"; +import config from "$config"; import fs from "fs"; import binanceFactory from "./binance"; import { broadcast } from "./sockets"; @@ -58,8 +59,3 @@ app.get("/rates", async (req, res, next) => { setInterval(() => { broadcast("rate", store.last); }, 1000); - -setInterval(() => { - binance.terminate(); - binance = require("./binance")(); -}, 360000); 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 }); |
