From 9121a73d4a5ee340f6c9d3b68186493b7d1bf29a Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 6 Sep 2022 10:30:03 -0700 Subject: missing imports --- index.js | 2 -- lib/rates.js | 2 +- lib/register.js | 5 ++++- routes/assets.js | 10 +++++----- routes/bitcoin/receive.js | 9 ++++++--- routes/invoices.js | 2 +- routes/lightning/receive.js | 3 ++- routes/liquid/receive.js | 35 ++++++++++++++++++++--------------- routes/users.js | 1 + 9 files changed, 40 insertions(+), 29 deletions(-) diff --git a/index.js b/index.js index 8a213099..d942cebe 100644 --- a/index.js +++ b/index.js @@ -8,9 +8,7 @@ import "./db"; import "./lib/sockets"; import "./lib/webhooks"; import "./lib/passport"; -import "./lib/register"; import "./lib/upload"; -import "./lib/send"; import "./lib/sync"; import "./routes/assets"; import "./routes/info"; diff --git a/lib/rates.js b/lib/rates.js index 5a8ba536..8679a08e 100644 --- a/lib/rates.js +++ b/lib/rates.js @@ -53,7 +53,7 @@ let fetchRates; })(); app.get("/rates", async (req, res, next) => { - res.send(rates); + res.send(store.rates); }); setInterval(() => { diff --git a/lib/register.js b/lib/register.js index 7f8a059d..60f8825f 100644 --- a/lib/register.js +++ b/lib/register.js @@ -1,8 +1,11 @@ +import config from "$config"; import { authenticator } from "otplib"; +import db from "$db"; import axios from "axios"; import bcrypt from "bcrypt"; +import { l } from "$lib/logging"; -export const register = async (user, ip, requireChallenge) => { +export default async (user, ip, requireChallenge) => { if (!(user && user.username)) throw new Error("Username required"); user.username = user.username.replace(/ /g, ""); diff --git a/routes/assets.js b/routes/assets.js index 826ff2d9..22bf71d0 100644 --- a/routes/assets.js +++ b/routes/assets.js @@ -238,7 +238,7 @@ app.post("/assets", auth, async (req, res) => { ); emit(user.username, "payment", asset_payment); - issuances[txid] = { + store.issuances[txid] = { user_id, asset, asset_amount: params.asset_amount, @@ -278,14 +278,14 @@ app.post("/assets", auth, async (req, res) => { ); emit(user.username, "payment", token_payment); - issuances[txid].token = token; - issuances[txid].token_amount = token_amount; - issuances[txid].token_payment_id = token_payment.id; + store.issuances[txid].token = token; + store.issuances[txid].token_amount = token_amount; + store.issuances[txid].token_payment_id = token_payment.id; } } }); - res.send(issuances[txid] ? issuances[txid] : { asset }); + res.send(store.issuances[txid] ? store.issuances[txid] : { asset }); } catch (e) { err("asset issuance failed", e.message, e.stack); res.code(500).send(e.message); diff --git a/routes/bitcoin/receive.js b/routes/bitcoin/receive.js index 15e21121..f39d43b5 100644 --- a/routes/bitcoin/receive.js +++ b/routes/bitcoin/receive.js @@ -1,4 +1,6 @@ import config from "$config"; +import db from "$db"; +import bc from "$lib/bitcoin"; import { emit } from "$lib/sockets"; import store from "$lib/store"; import { notify } from "$lib/notifications"; @@ -10,6 +12,7 @@ import { fromBase58 } from 'bip32'; import bitcoin from 'bitcoinjs-lib'; import { sendLiquid } from "$routes/liquid/send"; import { computeConversionFee } from './conversionFee'; +import { l, warn, err } from "$lib/logging"; const zmqRawBlock = zmq.socket("sub"); zmqRawBlock.connect(config.bitcoin.zmqrawblock); @@ -52,13 +55,13 @@ zmqRawTx.on("message", async (topic, message, sequence) => { } if ( - Object.keys(addresses).includes(address) && + Object.keys(store.addresses).includes(address) && !store.change.includes(address) ) { await db.transaction(async transaction => { let user = await db.User.findOne({ where: { - username: addresses[address] + username: store.addresses[address] }, transaction }); @@ -229,7 +232,7 @@ setInterval(async () => { notify(user, `${total} SAT payment confirmed`); callWebhook(p.invoice, p); - let c = convert[address]; + let c = store.convert[address]; if (address && c) { l( "bitcoin detected to conversion address", diff --git a/routes/invoices.js b/routes/invoices.js index e0cb48c9..b5926fec 100644 --- a/routes/invoices.js +++ b/routes/invoices.js @@ -40,7 +40,7 @@ app.post("/invoice", optionalAuth, async (req, res, next) => { if (liquidAddress) { l("conversion request for", liquidAddress, invoice.text); - convert[invoice.text] = { address: liquidAddress, tx }; + store.convert[invoice.text] = { address: liquidAddress, tx }; } if (!user) ({ user } = req); diff --git a/routes/lightning/receive.js b/routes/lightning/receive.js index 6bc26814..ed23516b 100644 --- a/routes/lightning/receive.js +++ b/routes/lightning/receive.js @@ -1,3 +1,4 @@ +import store from "$lib/store"; import { emit } from "$lib/sockets"; import config from "$config"; import { notify } from "$lib/notifications"; @@ -99,7 +100,7 @@ const handlePayment = async msg => { ); }); - let c = convert[msg.payment_request]; + let c = store.convert[msg.payment_request]; if (msg.payment_request && c) { l( "lightning detected for conversion request", diff --git a/routes/liquid/receive.js b/routes/liquid/receive.js index 11bab772..e624c53a 100644 --- a/routes/liquid/receive.js +++ b/routes/liquid/receive.js @@ -1,3 +1,4 @@ +import db from "$db"; import config from "$config"; import { toSats } from "$lib/utils"; import { emit } from "$lib/sockets"; @@ -5,19 +6,22 @@ import store from "$lib/store"; import { sendLiquid } from "$routes/liquid/send"; import { notify } from "$lib/notifications"; import { callWebhook } from "$lib/webhooks"; -import reverse from 'buffer-reverse'; -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 reverse from "buffer-reverse"; +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 { l, err, warn } from "$lib/logging"; +import lq from "$lib/liquid"; +import { getUser } from "$lib/utils"; const network = networks[ config.liquid.network === "mainnet" ? "liquid" : config.liquid.network ]; -import { computeConversionFee } from './conversionFee'; +import { computeConversionFee } from "./conversionFee"; const getAccount = async (params, transaction) => { let account = await db.Account.findOne({ @@ -172,13 +176,11 @@ zmqRawTx.on("message", async (topic, message, sequence) => { await user.save({ transaction }); const currency = invoice ? invoice.currency : user.currency; - const rate = invoice - ? invoice.rate - : store.rates[user.currency]; + const rate = invoice ? invoice.rate : store.rates[user.currency]; const tip = invoice ? invoice.tip : 0; const memo = invoice ? invoice.memo : ""; - payment = await db.Payment.create( + let payment = await db.Payment.create( { account_id: account.id, user_id: user.id, @@ -228,7 +230,7 @@ zmqRawBlock.on("message", async (topic, message, sequence) => { json = await lq.getBlock(hash, 2); json.tx.map(async tx => { - if (issuances[tx.txid]) { + if (store.issuances[tx.txid]) { await db.transaction(async transaction => { const { user_id, @@ -238,7 +240,7 @@ zmqRawBlock.on("message", async (topic, message, sequence) => { token, token_amount, token_payment_id - } = issuances[tx.txid]; + } = store.issuances[tx.txid]; const user = await getUserById(user_id); @@ -348,7 +350,10 @@ setInterval(async () => { { pending: Math.min(p.account.pending, total) }, { transaction } ); - await p.account.increment({ liquid_credits: computeConversionFee(total) }, { transaction }); + await p.account.increment( + { liquid_credits: computeConversionFee(total) }, + { transaction } + ); await p.account.reload({ transaction }); await p.save({ transaction }); @@ -375,7 +380,7 @@ setInterval(async () => { delete queue[hash]; }); - let c = convert[address]; + let c = store.convert[address]; if (address && c && p.account.asset === network.assetHash) { l( "liquid detected for conversion request", diff --git a/routes/users.js b/routes/users.js index dd62fad1..599d6837 100644 --- a/routes/users.js +++ b/routes/users.js @@ -20,6 +20,7 @@ import db from "$db"; import bc from "$lib/bitcoin"; import lq from "$lib/liquid"; import { emit } from "$lib/sockets"; +import register from "$lib/register"; const pick = (O, ...K) => K.reduce((o, k) => ((o[k] = O[k]), o), {}); -- cgit v1.2.3