From a440edf47c5902f16b442020cba05908180916af Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 6 Sep 2022 12:09:42 -0700 Subject: always import payment monitors --- routes/liquid/receive.js | 4 +- routes/payments.js | 102 ++++++++++++++++++++++------------------------- 2 files changed, 50 insertions(+), 56 deletions(-) diff --git a/routes/liquid/receive.js b/routes/liquid/receive.js index e624c53a..f3b8397f 100644 --- a/routes/liquid/receive.js +++ b/routes/liquid/receive.js @@ -11,11 +11,13 @@ import zmq from "zeromq/v5-compat"; import { Op } from "@sequelize/core"; import { fromBase58 } from "bip32"; import bitcoin from "bitcoinjs-lib"; -import { Block, networks, Transaction } from "liquidjs-lib"; +import liquidJs from "liquidjs-lib"; import { l, err, warn } from "$lib/logging"; import lq from "$lib/liquid"; import { getUser } from "$lib/utils"; +const { Block, networks, Transaction } = liquidJs; + const network = networks[ config.liquid.network === "mainnet" ? "liquid" : config.liquid.network diff --git a/routes/payments.js b/routes/payments.js index 6d4076cf..3e91e5fd 100644 --- a/routes/payments.js +++ b/routes/payments.js @@ -17,6 +17,10 @@ import btcRoutes from "./bitcoin/index"; import lnRoutes from "./lightning/index"; import lqRoutes from "./liquid/index"; +import "./bitcoin/receive"; +import "./lightning/receive"; +import "./liquid/receive"; + app.post("/send", auth, send); app.post("/sendToTokenHolders", auth, async (req, res, next) => { let { asset, amount } = req.body; @@ -31,12 +35,9 @@ app.post("/sendToTokenHolders", auth, async (req, res, next) => { }); let totalTokens = accounts.reduce((a, b) => a + b.balance, 0); - console.log("TOTAL TOKENS", totalTokens); let totalSats = Math.floor(amount / totalTokens); - console.log("TOTAL SATS", totalSats); - if (totalSats < 1) throw new Error("amount is too low to distribute"); for (let i = 0; i < accounts.length; i++) { @@ -55,58 +56,49 @@ app.get("/except", adminAuth, (req, res) => { res.send("updated exceptions"); }); -if (config.lna) { - app.post("/lightning/channel", lnRoutes.channel); - app.post("/lightning/invoice", lnRoutes.invoice); - app.post("/lightning/query", auth, lnRoutes.query); - app.post("/lightning/send", auth, lnRoutes.send); - import("./lightning/receive"); - - // if (config.lnurl) { - // let channelRequest = await import("$routes/lightning/channelRequest"); - // app.post("/lightning/channelRequest", channelRequest) - // } -} - -if (config.bitcoin) { - app.post("/bitcoin/broadcast", optionalAuth, btcRoutes.broadcast); - app.get("/bitcoin/generate", auth, btcRoutes.generate); - app.post("/bitcoin/sweep", auth, btcRoutes.sweep); - app.post("/bitcoin/fee", auth, btcRoutes.fee); - app.post("/bitcoin/send", auth, btcRoutes.send); - import("./bitcoin/receive"); - - setTimeout(async () => { - try { - const address = await bc.getNewAddress(); - const { hdkeypath } = await bc.getAddressInfo(address); - const parts = hdkeypath.split("/"); - store.bcAddressIndex = parts[parts.length - 1].replace("'", ""); - } catch (e) { - console.error(e); - } - }, 50); -} - -if (config.liquid) { - app.post("/liquid/broadcast", optionalAuth, lqRoutes.broadcast); - app.get("/liquid/generate", auth, lqRoutes.generate); - // app.post("/liquid/fee", auth, lqRoutes.fee); - app.post("/liquid/send", auth, lqRoutes.send); - // app.post("/taxi", auth, lqRoutes.taxi); - import("./liquid/receive"); - - setTimeout(async () => { - try { - const address = await lq.getNewAddress(); - const { hdkeypath } = await lq.getAddressInfo(address); - const parts = hdkeypath.split("/"); - store.lqAddressIndex = parts[parts.length - 1].slice(0, -1); - } catch (e) { - warn("Problem getting liquid address index", e.message); - } - }, 50); -} +app.post("/lightning/channel", lnRoutes.channel); +app.post("/lightning/invoice", lnRoutes.invoice); +app.post("/lightning/query", auth, lnRoutes.query); +app.post("/lightning/send", auth, lnRoutes.send); + +// if (config.lnurl) { +// let channelRequest = await import("$routes/lightning/channelRequest"); +// app.post("/lightning/channelRequest", channelRequest) +// } + +app.post("/bitcoin/broadcast", optionalAuth, btcRoutes.broadcast); +app.get("/bitcoin/generate", auth, btcRoutes.generate); +app.post("/bitcoin/sweep", auth, btcRoutes.sweep); +app.post("/bitcoin/fee", auth, btcRoutes.fee); +app.post("/bitcoin/send", auth, btcRoutes.send); + +setTimeout(async () => { + try { + const address = await bc.getNewAddress(); + const { hdkeypath } = await bc.getAddressInfo(address); + const parts = hdkeypath.split("/"); + store.bcAddressIndex = parts[parts.length - 1].replace("'", ""); + } catch (e) { + console.error(e); + } +}, 50); + +app.post("/liquid/broadcast", optionalAuth, lqRoutes.broadcast); +app.get("/liquid/generate", auth, lqRoutes.generate); +// app.post("/liquid/fee", auth, lqRoutes.fee); +app.post("/liquid/send", auth, lqRoutes.send); +// app.post("/taxi", auth, lqRoutes.taxi); + +setTimeout(async () => { + try { + const address = await lq.getNewAddress(); + const { hdkeypath } = await lq.getAddressInfo(address); + const parts = hdkeypath.split("/"); + store.lqAddressIndex = parts[parts.length - 1].slice(0, -1); + } catch (e) { + warn("Problem getting liquid address index", e.message); + } +}, 50); app.get("/payments", auth, async (req, res) => { if (!req.user.account_id) return res.send([]); -- cgit v1.2.3