diff options
| author | Adam Soltys <[email protected]> | 2022-09-06 09:18:19 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2022-09-06 09:18:19 -0700 |
| commit | 8a080ef9a198799e7ee31cf81f92afd5495e4074 (patch) | |
| tree | 8da36c843846f47918a5acadd95da30d8d63bcc6 | |
| parent | 412df5f844de11b3fc71bb7ffaf9c8e1d9f19d65 (diff) | |
| download | coinos-server-8a080ef9a198799e7ee31cf81f92afd5495e4074.tar.gz coinos-server-8a080ef9a198799e7ee31cf81f92afd5495e4074.zip | |
missing imports
| -rw-r--r-- | index.js | 2 | ||||
| -rw-r--r-- | lib/mail.js | 1 | ||||
| -rw-r--r-- | lib/send.js | 1 | ||||
| -rw-r--r-- | lib/sync.js | 2 | ||||
| -rw-r--r-- | routes/assets.js | 1 | ||||
| -rw-r--r-- | routes/bitcoin/broadcast.js | 1 | ||||
| -rw-r--r-- | routes/bitcoin/fee.js | 1 | ||||
| -rw-r--r-- | routes/bitcoin/receive.js | 7 | ||||
| -rw-r--r-- | routes/bitcoin/send.js | 1 | ||||
| -rw-r--r-- | routes/funding.js | 1 | ||||
| -rw-r--r-- | routes/lightning/query.js | 2 | ||||
| -rw-r--r-- | routes/lightning/receive.js | 1 | ||||
| -rw-r--r-- | routes/liquid/broadcast.js | 2 | ||||
| -rw-r--r-- | routes/liquid/fee.js | 1 | ||||
| -rw-r--r-- | routes/liquid/receive.js | 3 | ||||
| -rw-r--r-- | routes/liquid/send.js | 2 | ||||
| -rw-r--r-- | routes/lnurl.js | 1 | ||||
| -rw-r--r-- | routes/payments.js | 155 | ||||
| -rw-r--r-- | routes/send.js | 1 | ||||
| -rw-r--r-- | routes/swaps.js | 1 | ||||
| -rw-r--r-- | routes/users.js | 18 |
21 files changed, 116 insertions, 89 deletions
@@ -23,8 +23,6 @@ if (config.lna) store.networks.push("lightning"); import "./lib/rates"; import "./lib/notifications"; -console.log("LNURL?", config.lnurl) - // if (config.imap) import("./lib/mail"); // if (config.lnurl) import("./routes/lnurl"); // if (config.mailgun) import("./routes/funding"); diff --git a/lib/mail.js b/lib/mail.js index 9d4061b4..fdece056 100644 --- a/lib/mail.js +++ b/lib/mail.js @@ -1,3 +1,4 @@ +import { emit } from "$lib/sockets"; import app from "$app"; import config from "$config"; import fs from "fs"; diff --git a/lib/send.js b/lib/send.js index f8c53854..a4280401 100644 --- a/lib/send.js +++ b/lib/send.js @@ -1,3 +1,4 @@ +import { emit } from "$lib/sockets"; import store from "./store"; import bolt11 from "bolt11"; import { Op } from "@sequelize/core"; diff --git a/lib/sync.js b/lib/sync.js index 4aa8d40d..212a1a42 100644 --- a/lib/sync.js +++ b/lib/sync.js @@ -1,3 +1,5 @@ +import { toSats } from "$lib/utils"; +import { emit } from "$lib/sockets"; import db from "$db/db"; import app from "$app"; import { differenceInDays } from "date-fns"; diff --git a/routes/assets.js b/routes/assets.js index 43098004..541c9625 100644 --- a/routes/assets.js +++ b/routes/assets.js @@ -1,3 +1,4 @@ +import { emit } from "$lib/sockets"; import store from "$lib/store"; import db from "$db"; import config from "$config"; diff --git a/routes/bitcoin/broadcast.js b/routes/bitcoin/broadcast.js index ec733101..e4c7ba62 100644 --- a/routes/bitcoin/broadcast.js +++ b/routes/bitcoin/broadcast.js @@ -1,3 +1,4 @@ +import { emit } from "$lib/sockets"; import store from "$lib/store"; export default async (req, res) => { try { diff --git a/routes/bitcoin/fee.js b/routes/bitcoin/fee.js index a47ac05e..af622ca5 100644 --- a/routes/bitcoin/fee.js +++ b/routes/bitcoin/fee.js @@ -1,3 +1,4 @@ +import { emit } from "$lib/sockets"; import buildTx from "$lib/buildtx"; export default async (req, res) => { diff --git a/routes/bitcoin/receive.js b/routes/bitcoin/receive.js index de98170c..15e21121 100644 --- a/routes/bitcoin/receive.js +++ b/routes/bitcoin/receive.js @@ -1,4 +1,6 @@ -import { rates } from "$lib/store"; +import config from "$config"; +import { emit } from "$lib/sockets"; +import store from "$lib/store"; import { notify } from "$lib/notifications"; import { callWebhook } from "$lib/webhooks"; import reverse from 'buffer-reverse'; @@ -7,6 +9,7 @@ import { Op } from '@sequelize/core'; import { fromBase58 } from 'bip32'; import bitcoin from 'bitcoinjs-lib'; import { sendLiquid } from "$routes/liquid/send"; +import { computeConversionFee } from './conversionFee'; const zmqRawBlock = zmq.socket("sub"); zmqRawBlock.connect(config.bitcoin.zmqrawblock); @@ -24,9 +27,9 @@ const network = const queue = {}; const seen = []; -import { computeConversionFee } from './conversionFee'; zmqRawTx.on("message", async (topic, message, sequence) => { + console.log("TX", message) const hex = message.toString("hex"); let tx = bitcoin.Transaction.fromHex(message); diff --git a/routes/bitcoin/send.js b/routes/bitcoin/send.js index 1992bbde..51d702fd 100644 --- a/routes/bitcoin/send.js +++ b/routes/bitcoin/send.js @@ -1,3 +1,4 @@ +import { toSats } from "$lib/utils"; import store from "$lib/store"; import config from "$config"; const btc = config.liquid.btcasset; diff --git a/routes/funding.js b/routes/funding.js index b2275b48..9647b301 100644 --- a/routes/funding.js +++ b/routes/funding.js @@ -1,3 +1,4 @@ +import { emit } from "$lib/sockets"; import app from "$app"; import config from "$config"; import mailgunFactory from 'mailgun-js'; diff --git a/routes/lightning/query.js b/routes/lightning/query.js index d01fe442..c5456a6f 100644 --- a/routes/lightning/query.js +++ b/routes/lightning/query.js @@ -1,3 +1,5 @@ +import { emit } from "$lib/sockets"; + export default async (req, res) => { const { payreq } = req.body; diff --git a/routes/lightning/receive.js b/routes/lightning/receive.js index c01592d2..6bc26814 100644 --- a/routes/lightning/receive.js +++ b/routes/lightning/receive.js @@ -1,3 +1,4 @@ +import { emit } from "$lib/sockets"; import config from "$config"; import { notify } from "$lib/notifications"; import { callWebhook } from "$lib/webhooks"; diff --git a/routes/liquid/broadcast.js b/routes/liquid/broadcast.js index 5f44558e..03a71b2b 100644 --- a/routes/liquid/broadcast.js +++ b/routes/liquid/broadcast.js @@ -1,4 +1,6 @@ +import { emit } from "$lib/sockets"; import store from "$lib/store"; + export default async (req, res) => { try { const { user } = req; diff --git a/routes/liquid/fee.js b/routes/liquid/fee.js index 7c461d70..34ee2553 100644 --- a/routes/liquid/fee.js +++ b/routes/liquid/fee.js @@ -1,3 +1,4 @@ +import { emit } from "$lib/sockets"; import buildTx from "$lib/buildliquidtx"; liquidTx = async ({ address, asset, amount, feeRate, replaceable, user }) => { diff --git a/routes/liquid/receive.js b/routes/liquid/receive.js index 8b39bb19..11bab772 100644 --- a/routes/liquid/receive.js +++ b/routes/liquid/receive.js @@ -1,3 +1,6 @@ +import config from "$config"; +import { toSats } from "$lib/utils"; +import { emit } from "$lib/sockets"; import store from "$lib/store"; import { sendLiquid } from "$routes/liquid/send"; import { notify } from "$lib/notifications"; diff --git a/routes/liquid/send.js b/routes/liquid/send.js index 2e91f013..5297de1c 100644 --- a/routes/liquid/send.js +++ b/routes/liquid/send.js @@ -1,3 +1,5 @@ +import { toSats } from "$lib/utils"; +import { emit } from "$lib/sockets"; import store from "$lib/store"; import config from "$config"; const btc = config.liquid.btcasset; diff --git a/routes/lnurl.js b/routes/lnurl.js index 467c39dc..d7bdcfc2 100644 --- a/routes/lnurl.js +++ b/routes/lnurl.js @@ -1,3 +1,4 @@ +import { emit } from "$lib/sockets"; import store from "$lib/store"; import app from "$app"; import config from "$config"; diff --git a/routes/payments.js b/routes/payments.js index d8518da4..4939394f 100644 --- a/routes/payments.js +++ b/routes/payments.js @@ -56,7 +56,6 @@ app.get("/except", adminAuth, (req, res) => { }); if (config.lna) { - console.log("LIGHTNING ROUTES") app.post("/lightning/channel", lnRoutes.channel); app.post("/lightning/invoice", lnRoutes.invoice); app.post("/lightning/query", auth, lnRoutes.query); @@ -68,80 +67,80 @@ if (config.lna) { // 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.get("/payments", auth, async (req, res) => { -// if (!req.user.account_id) return res.send([]); -// let payments = await db.Payment.findAll({ -// where: { -// account_id: req.user.account_id -// }, -// order: [["id", "DESC"]], -// include: { -// model: db.Account, -// as: "account" -// } -// }); -// -// res.send(payments); -// }); -// -// app.get("/payment/:redeemcode", async (req, res) => { -// try { -// const { redeemcode } = req.params; -// let payment = await db.Payment.findOne({ -// where: { -// redeemcode -// }, -// include: { -// model: db.Account, -// as: "account" -// } -// }); -// -// if (!payment) fail("invalid code"); -// -// res.send(payment); -// } catch (e) { -// res.code(500).send(e.message); -// } -// }); + +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.get("/payments", auth, async (req, res) => { + if (!req.user.account_id) return res.send([]); + let payments = await db.Payment.findAll({ + where: { + account_id: req.user.account_id + }, + order: [["id", "DESC"]], + include: { + model: db.Account, + as: "account" + } + }); + + res.send(payments); +}); + +app.get("/payment/:redeemcode", async (req, res) => { + try { + const { redeemcode } = req.params; + let payment = await db.Payment.findOne({ + where: { + redeemcode + }, + include: { + model: db.Account, + as: "account" + } + }); + + if (!payment) fail("invalid code"); + + res.send(payment); + } catch (e) { + res.code(500).send(e.message); + } +}); diff --git a/routes/send.js b/routes/send.js index 7b7adc5c..d2ec3add 100644 --- a/routes/send.js +++ b/routes/send.js @@ -1,3 +1,4 @@ +import { emit } from "$lib/sockets"; import store from "$lib/store"; import { callWebhook } from "$lib/webhooks"; import axios from "axios"; diff --git a/routes/swaps.js b/routes/swaps.js index 5deeec56..31387bec 100644 --- a/routes/swaps.js +++ b/routes/swaps.js @@ -1,3 +1,4 @@ +import { emit } from "$lib/sockets"; import app from "$app"; import config from "$config"; import { auth, optionalAuth } from "$lib/passport"; diff --git a/routes/users.js b/routes/users.js index 5e27be49..ca1f3a02 100644 --- a/routes/users.js +++ b/routes/users.js @@ -1,5 +1,6 @@ import app from "$app"; import config from "$config"; +import store from "$lib/store"; import { auth, optionalAuth } from "$lib/passport"; import { getUser } from "$lib/utils"; import axios from "axios"; @@ -9,13 +10,16 @@ import { authenticator } from "otplib"; import getAccount from "$lib/account"; import Sequelize from "@sequelize/core"; import bitcoin from "bitcoinjs-lib"; -// import liquid from 'liquidjs-lib'; +import liquid from 'liquidjs-lib'; import { fromBase58, fromPrivateKey } from "bip32"; import { Mutex } from "async-mutex"; import bip32 from "bip32"; import whitelist from "$lib/whitelist"; import { l, err, warn } from "$lib/logging"; import db from "$db"; +import bc from "$lib/bitcoin"; +import lq from "$lib/liquid"; +import { emit } from "$lib/sockets"; const pick = (O, ...K) => K.reduce((o, k) => ((o[k] = O[k]), o), {}); @@ -153,7 +157,7 @@ app.post("/user", auth, async (req, res) => { err("username taken", username, user.username, exists.username); return res.code(500).send("Username taken"); } else { - sockets[username] = sockets[user.username]; + store.sockets[username] = store.sockets[user.username]; if (user.username !== username) l("changing username", user.username, username); user.username = username; @@ -387,20 +391,20 @@ app.get("/address", async (req, res) => { return res.code(500).send("Bitcoin not configured"); address = await bc.getNewAddress("", type); - bcAddressIndex = i + 1; + store.bcAddressIndex = i + 1; return res.send({ address }); p = bitcoin.payments; n = prod ? bitcoin.networks["bitcoin"] : bitcoin.networks["regtest"]; - i = parseInt(app.get("bcAddressIndex")); + i = parseInt(store.bcAddressIndex); hd = fromBase58(config.bitcoin.masterkey, n).derivePath(`m/0'/0'/${i}'`); // async request to node to bump its internal index but don't use result bc.getNewAddress().catch(console.error); res.send({ address, confidentialAddress }); - bcAddressIndex = i + 1; + store.bcAddressIndex = i + 1; } else if (network === "liquid") { p = liquid.payments; n = @@ -414,7 +418,7 @@ app.get("/address", async (req, res) => { warn("Problem bumping liquid address index", e.message) ); - i = parseInt(app.get("lqAddressIndex")); + i = parseInt(store.lqAddressIndex); if (!i) { const { hdkeypath } = await lq.getAddressInfo(await lq.getNewAddress()); @@ -426,7 +430,7 @@ app.get("/address", async (req, res) => { if (!i) throw new Error("Problem generating address"); hd = fromBase58(config.liquid.masterkey, n).derivePath(`m/0'/0'/${i}'`); - lqAddressIndex = i + 1; + store.lqAddressIndex = i + 1; } else { throw new Error("Unsupported network"); } |
