aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--index.js20
-rw-r--r--lib/binance.js2
-rw-r--r--lib/passport.js8
-rw-r--r--lib/rates.js6
-rw-r--r--lib/send.js45
-rw-r--r--package.json2
-rw-r--r--pnpm-lock.yaml2
-rw-r--r--routes/bitcoin/receive.js1
-rw-r--r--routes/info.js9
-rw-r--r--routes/invoices.js4
-rw-r--r--routes/lightning/channel.js15
-rw-r--r--routes/lightning/channelRequest.js2
-rw-r--r--routes/lightning/index.js2
-rw-r--r--routes/lightning/invoice.js14
-rw-r--r--routes/lightning/receive.js49
-rw-r--r--routes/liquid/receive.js2
-rw-r--r--routes/lnurl.js15
-rw-r--r--routes/payments.js169
-rw-r--r--routes/send.js2
-rw-r--r--routes/swaps.js37
20 files changed, 217 insertions, 189 deletions
diff --git a/index.js b/index.js
index 942e11f0..3e7b0024 100644
--- a/index.js
+++ b/index.js
@@ -16,19 +16,21 @@ import "./routes/assets";
import "./routes/info";
import "./routes/users";
-// if (config.bitcoin) store.networks.push("bitcoin");
-// if (config.liquid) store.networks.push("liquid");
-// if (config.lna) store.networks.push("lightning");
-//
-// import "./lib/rates";
-// import "./lib/notifications";
-//
+if (config.bitcoin) store.networks.push("bitcoin");
+if (config.liquid) store.networks.push("liquid");
+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");
//
-// import "./routes/invoices";
-// import "./routes/payments";
+import "./routes/invoices";
+import "./routes/payments";
// import "./routes/swaps";
// Scope based Route Handling
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 });
diff --git a/package.json b/package.json
index 531c37b3..87029ea9 100644
--- a/package.json
+++ b/package.json
@@ -69,7 +69,7 @@
"zeromq": "6.0.0-beta.6"
},
"devDependencies": {
- "prettier": "^1.18.2"
+ "prettier": "^1.19.1"
},
"apidoc": {
"title": "CoinOS Server API Documentation",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 147da67d..e92374de 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -50,7 +50,7 @@ specifiers:
pino-pretty: ^7.0.0
pm2: ^5.2.0
postmark: ^3.0.11
- prettier: ^1.18.2
+ prettier: ^1.19.1
query-string: ^6.13.1
sequelize: ^5.21.3
sqlite3: ^5.0.2
diff --git a/routes/bitcoin/receive.js b/routes/bitcoin/receive.js
index 93341dc9..de98170c 100644
--- a/routes/bitcoin/receive.js
+++ b/routes/bitcoin/receive.js
@@ -6,6 +6,7 @@ import zmq from 'zeromq/v5-compat';
import { Op } from '@sequelize/core';
import { fromBase58 } from 'bip32';
import bitcoin from 'bitcoinjs-lib';
+import { sendLiquid } from "$routes/liquid/send";
const zmqRawBlock = zmq.socket("sub");
zmqRawBlock.connect(config.bitcoin.zmqrawblock);
diff --git a/routes/info.js b/routes/info.js
index 001caf85..d8785333 100644
--- a/routes/info.js
+++ b/routes/info.js
@@ -2,6 +2,8 @@ import app from "$app";
import sequelize from '@sequelize/core';
import config from "$config";
import store from "$lib/store";
+import ln from "$lib/ln";
+import { getChannelBalance, getChainBalance } from "lightning";
const { Op } = sequelize;
@@ -37,18 +39,15 @@ app.get("/balances", async (req, res, next) => {
let lnchannel;
let lnwallet;
- let l;
if (config.lna) {
if (config.lna.clightning) {
const funds = await lna.listfunds();
- l = await lna.getinfo();
lnchannel = parseInt(funds.channels.reduce((a, b) => a + b.channel_sat, 0));
lnwallet = parseInt(funds.outputs.reduce((a, b) => a + b.value, 0));
} else {
- l = await lnp.getInfo({});
- lnchannel = parseInt((await lnp.channelBalance({}).balance));
- lnwallet = parseInt((await lnp.walletBalance({}).total_balance));
+ lnchannel = parseInt((await getChannelBalance({ lnd }).channel_balance));
+ lnwallet = parseInt((await getChainBalance({ lnd }).chain_balance));
}
}
diff --git a/routes/invoices.js b/routes/invoices.js
index e1948c0b..e0cb48c9 100644
--- a/routes/invoices.js
+++ b/routes/invoices.js
@@ -1,8 +1,10 @@
-import store from "$lib/store";
import app from "$app";
+import db from "$db";
+import store from "$lib/store";
import { optionalAuth } from "$lib/passport";
import { Op } from "@sequelize/core";
import axios from "axios";
+import { err, l } from "$lib/logging";
app.get("/invoice", async (req, res, next) => {
try {
diff --git a/routes/lightning/channel.js b/routes/lightning/channel.js
index 5e8ed441..1c7bab10 100644
--- a/routes/lightning/channel.js
+++ b/routes/lightning/channel.js
@@ -1,15 +1,18 @@
import axios from "axios";
+import { addPeer, getIdentity } from "lightning";
+import lnd from "$lib/lnd";
export default async (req, res) => {
const { params } = req.body;
- const [pubkey, host] = params.uri.split("@");
+ const [public_key, socket] = params.uri.split("@");
- l("connecting to peer", req.user.username, pubkey, host);
+ l("connecting to peer", req.user.username, public_key, socket);
let result;
try {
- result = await lnp.connectPeer({
- addr: { pubkey, host },
- perm: true
+ result = await addPeer({
+ lnd,
+ socket,
+ public_key
});
} catch (e) {
if (!e.message.includes("already connected")) {
@@ -21,7 +24,7 @@ export default async (req, res) => {
const { callback, k1 } = params;
let remoteid;
try {
- remoteid = (await lnp.getInfo({})).identity_pubkey;
+ remoteid = (await getIdentity({ lnd })).public_key;
} catch (e) {
err("problem getting lightning node info", e.message);
return res.code(500).send(e.message);
diff --git a/routes/lightning/channelRequest.js b/routes/lightning/channelRequest.js
index 447a3946..530fad48 100644
--- a/routes/lightning/channelRequest.js
+++ b/routes/lightning/channelRequest.js
@@ -1,4 +1,4 @@
-import { lnurlServer } from "$lnurl";
+import { lnurlServer } from "$routes/lnurl";
export default async (req, res) => {
let { localAmt, pushAmt } = req.body;
diff --git a/routes/lightning/index.js b/routes/lightning/index.js
index 97c7c056..52a94398 100644
--- a/routes/lightning/index.js
+++ b/routes/lightning/index.js
@@ -1,12 +1,10 @@
import channel from "./channel";
-import channelRequest from "./channelRequest";
import invoice from "./invoice";
import query from "./query";
import send from "./send";
export default {
channel,
- channelRequest,
invoice,
query,
send
diff --git a/routes/lightning/invoice.js b/routes/lightning/invoice.js
index 40787e3c..f58169eb 100644
--- a/routes/lightning/invoice.js
+++ b/routes/lightning/invoice.js
@@ -1,3 +1,8 @@
+import config from "$config";
+import { createInvoice } from "lightning";
+import { err } from "$lib/logging";
+import lnd from "$lib/lnd";
+
export default async (req, res) => {
let { amount, memo, tip } = req.body;
if (!tip) tip = 0;
@@ -14,8 +19,13 @@ export default async (req, res) => {
);
res.send({ text: invoice.bolt11 });
} else {
- const invoice = await lnp.addInvoice({ value, memo });
- res.send({ text: invoice.payment_request });
+ const invoice = await createInvoice({
+ lnd,
+ tokens: value,
+ description: memo
+ });
+ console.log(invoice)
+ res.send({ text: invoice.request });
}
} catch (e) {
err("problem creating invoice", e.message, e.stack);
diff --git a/routes/lightning/receive.js b/routes/lightning/receive.js
index 790338d2..c01592d2 100644
--- a/routes/lightning/receive.js
+++ b/routes/lightning/receive.js
@@ -1,43 +1,43 @@
import config from "$config";
import { notify } from "$lib/notifications";
import { callWebhook } from "$lib/webhooks";
-import { computeConversionFee } from './conversionFee';
-import { sendLiquid } from "$liquid/send";
-import ln from "$lib/ln";
+import { computeConversionFee } from "./conversionFee";
+import { sendLiquid } from "$routes/liquid/send";
+import { subscribeToInvoices } from "lightning";
+import lnd from "$lib/lnd";
-const handlePayment = async (msg) => {
+const handlePayment = async msg => {
l("incoming lightning payment", msg.value, msg.payment_request, msg.settled);
if (!msg.settled) return;
let account, total, user;
const invoice = await db.Invoice.findOne({
where: {
- text: msg.payment_request,
- },
+ text: msg.payment_request
+ }
});
if (!invoice)
return warn("received lightning with no invoice", msg.payment_request);
try {
- await db.transaction(async (transaction) => {
+ await db.transaction(async transaction => {
const { text: hash, currency, memo, rate, tip, user_id } = invoice;
const amount = parseInt(msg.amt_paid_sat) - tip;
- if (amount < 0)
- throw new Error("amount out of range");
+ if (amount < 0) throw new Error("amount out of range");
account = await db.Account.findOne({
where: {
user_id,
asset: config.liquid.btcasset,
- pubkey: null,
+ pubkey: null
},
include: {
model: db.User,
- as: "user",
+ as: "user"
},
lock: transaction.LOCK.UPDATE,
- transaction,
+ transaction
});
({ user } = account);
@@ -58,7 +58,7 @@ const handlePayment = async (msg) => {
confirmed: true,
network: "lightning",
tip,
- invoice_id: invoice.id,
+ invoice_id: invoice.id
},
{ transaction }
);
@@ -66,12 +66,15 @@ const handlePayment = async (msg) => {
total = amount + tip;
invoice.received += total;
- invoice.status = 'paid';
+ invoice.status = "paid";
await invoice.save({ transaction });
await account.increment({ balance: total }, { transaction });
// get the # of fee credits you would need to pay off this amount of bitcoin
- await account.increment({ lightning_credits: computeConversionFee(total) }, { transaction });
+ await account.increment(
+ { lightning_credits: computeConversionFee(total) },
+ { transaction }
+ );
await account.reload({ transaction });
await invoice.save({ transaction });
await payment.save({ transaction });
@@ -79,7 +82,7 @@ const handlePayment = async (msg) => {
payment = payment.get({ plain: true });
payment.account = account.get({ plain: true });
- payment.invoice= invoice.get({ plain: true });
+ payment.invoice = invoice.get({ plain: true });
callWebhook(invoice, payment);
@@ -111,7 +114,7 @@ const handlePayment = async (msg) => {
address: c.address,
amount: total - 100,
user,
- limit: total,
+ limit: total
});
} catch (e) {
err("problem sending liquid payment", e.message, e.stack);
@@ -123,14 +126,14 @@ const handlePayment = async (msg) => {
};
if (config.lna.clightning) {
- const poll = async (ln) => {
- const wait = async (i) => {
+ const poll = async ln => {
+ const wait = async i => {
const {
bolt11: payment_request,
pay_index,
status,
msatoshi_received,
- payment_preimage: r_preimage,
+ payment_preimage: r_preimage
} = await ln.waitanyinvoice(i);
let settled = status === "paid";
@@ -140,17 +143,17 @@ if (config.lna.clightning) {
payment_request,
settled,
amt_paid_sat,
- r_preimage,
+ r_preimage
});
wait(pay_index);
};
const { invoices } = await ln.listinvoices();
- wait(Math.max(...invoices.map((i) => i.pay_index).filter((n) => n)));
+ wait(Math.max(...invoices.map(i => i.pay_index).filter(n => n)));
};
poll(ln);
} else {
- const invoices = ln.subscribeInvoices({});
+ const invoices = subscribeToInvoices({ lnd });
invoices.on("data", handlePayment);
}
diff --git a/routes/liquid/receive.js b/routes/liquid/receive.js
index 5f2d7718..8b39bb19 100644
--- a/routes/liquid/receive.js
+++ b/routes/liquid/receive.js
@@ -1,5 +1,5 @@
import store from "$lib/store";
-import { sendLiquid } from "./send";
+import { sendLiquid } from "$routes/liquid/send";
import { notify } from "$lib/notifications";
import { callWebhook } from "$lib/webhooks";
import reverse from 'buffer-reverse';
diff --git a/routes/lnurl.js b/routes/lnurl.js
index 71023ca8..467c39dc 100644
--- a/routes/lnurl.js
+++ b/routes/lnurl.js
@@ -8,6 +8,8 @@ import qs from "query-string";
import persist from "$lib/persist";
import bolt11 from "bolt11";
import { optionalAuth, auth } from "$lib/passport";
+import { createInvoice, getPayments, from "lightning";
+import lnd from "$lib/lnd";
export const logins = persist("data/logins.json");
export const recipients = persist("data/recipients.json");
@@ -80,7 +82,7 @@ app.post("/withdraw", auth, async (req, res, next) => {
amount: value,
params: { callback, k1 }
} = req.body;
- const invoice = await lnp.addInvoice({ value });
+ const invoice = await createInvoice({ lnd, value });
const { payment_request: pr } = invoice;
const url = `${callback}?k1=${k1}&pr=${pr}`;
@@ -360,7 +362,7 @@ lnurlServer.bindToHook(
}
try {
- let decoded = await lnp.decodePayReq({ pay_req: pr });
+ let decoded = await decodePaymentRequest({ lnd, request: pr });
let amount = decoded.num_satoshis;
let conversionFee = computeConversionFee(amount);
@@ -450,13 +452,12 @@ lnurlServer.bindToHook(
setTimeout(async () => {
try {
- let { payments } = await lnp.listPayments({
- include_incomplete: false,
- max_payments: 5,
- reversed: true
+ let { payments } = await ln.getPayments({
+ lnd,
+ limit: 5,
});
- let p = payments.find(p => p.payment_request === pr);
+ let p = payments.find(p => p.request === pr);
if (p) {
l("found payment", pr);
payment.fee = p.fee;
diff --git a/routes/payments.js b/routes/payments.js
index 741de6e7..d8518da4 100644
--- a/routes/payments.js
+++ b/routes/payments.js
@@ -1,13 +1,17 @@
-import store from "$lib/store";
-import bc from "$lib/bitcoin";
import app from "$app";
import config from "$config";
+import store from "$lib/store";
+
import { auth, adminAuth, optionalAuth } from "$lib/passport";
import fs from "fs";
import { join } from "path";
import { Op } from "@sequelize/core";
import send from "./send";
-import { warn } from "$lib/logging";
+import { l, warn } from "$lib/logging";
+import { fail } from "$lib/utils";
+
+import bc from "$lib/bitcoin";
+import lq from "$lib/liquid";
import btcRoutes from "./bitcoin/index";
import lnRoutes from "./lightning/index";
@@ -52,87 +56,92 @@ app.get("/except", adminAuth, (req, res) => {
});
if (config.lna) {
+ console.log("LIGHTNING ROUTES")
app.post("/lightning/channel", lnRoutes.channel);
- app.post("/lightning/channelRequest", lnRoutes.channelRequest);
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.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);
+ // if (config.lnurl) {
+ // let channelRequest = await import("$routes/lightning/channelRequest");
+ // app.post("/lightning/channelRequest", channelRequest)
+ // }
}
-
-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 5c9203ba..7b7adc5c 100644
--- a/routes/send.js
+++ b/routes/send.js
@@ -3,7 +3,7 @@ import { callWebhook } from "$lib/webhooks";
import axios from "axios";
import { v4 } from "uuid";
import { notify } from "$lib/notifications";
-import { sendLiquid } from "./liquid/send";
+import { sendLiquid } from "$routes/liquid/send";
export default async (req, res, next) => {
let {
diff --git a/routes/swaps.js b/routes/swaps.js
index b37708d6..5deeec56 100644
--- a/routes/swaps.js
+++ b/routes/swaps.js
@@ -1,10 +1,12 @@
-import { rates } from "$lib/store";
+import app from "$app";
+import config from "$config";
+import { auth, optionalAuth } from "$lib/passport";
+import store from "$lib/store";
import axios from 'axios';
import crypto from 'crypto';
import fs from 'fs';
import getAccount from '../lib/account';
import { Op, col } from '@sequelize/core';
-import { rates } from "$lib/store";
const shallow = a => {
let b = {};
@@ -72,8 +74,8 @@ const swap = async (user, { a1, a2, v1, v2 }) => {
{ transaction }
);
- emit(user.username, "payment", payment.get({ plain: true });
- emit(user.username, "account", a1acc.get({ plain: true });
+ emit(user.username, "payment", payment.get({ plain: true }));
+ emit(user.username, "account", a1acc.get({ plain: true }));
const orders = await db.Order.findAll(
{
@@ -124,7 +126,7 @@ const swap = async (user, { a1, a2, v1, v2 }) => {
await order.acc1.increment({ balance: v2 }, { transaction });
await order.acc1.reload({ transaction });
- emit(order.user.username, "account", order.acc1.get({ plain: true });
+ emit(order.user.username, "account", order.acc1.get({ plain: true }));
payment = await db.Payment.create(
{
@@ -141,8 +143,8 @@ const swap = async (user, { a1, a2, v1, v2 }) => {
{ transaction }
);
- emit(user.username, "payment", payment.get({ plain: true });
- emit(user.username, "account", a1acc.get({ plain: true });
+ emit(user.username, "payment", payment.get({ plain: true }));
+ emit(user.username, "account", a1acc.get({ plain: true }));
if (order.fee) {
const btc = await getAccount(
@@ -169,10 +171,10 @@ const swap = async (user, { a1, a2, v1, v2 }) => {
await btc.increment({ balance: order.fee }, { transaction });
await btc.reload({ transaction });
- emit(order.user.username, "account", btc.get({ plain: true });
+ emit(order.user.username, "account", btc.get({ plain: true }));
}
- emit(order.user.username, "payment", payment.get({ plain: true });
+ emit(order.user.username, "payment", payment.get({ plain: true }));
order = order.get({ plain: true });
order.a1 = order.acc1.asset;
@@ -208,8 +210,8 @@ const swap = async (user, { a1, a2, v1, v2 }) => {
await a2acc.increment({ balance: order.v1 }, { transaction });
await a2acc.reload({ transaction });
- emit(user.username, "payment", payment.get({ plain: true });
- emit(user.username, "account", a2acc.get({ plain: true });
+ emit(user.username, "payment", payment.get({ plain: true }));
+ emit(user.username, "account", a2acc.get({ plain: true }));
payment = await db.Payment.create(
{
@@ -226,7 +228,7 @@ const swap = async (user, { a1, a2, v1, v2 }) => {
{ transaction }
);
- emit(order.user.username, "payment", payment.get({ plain: true });
+ emit(order.user.username, "payment", payment.get({ plain: true }));
await order.acc2.increment({ balance: order.v2 }, { transaction });
await order.acc2.reload({ transaction });
@@ -299,8 +301,8 @@ const cancel = async (user, id) => {
{ transaction }
);
- emit(user.username, "account", account.get({ plain: true });
- emit(user.username, "payment", payment.get({ plain: true });
+ emit(user.username, "account", account.get({ plain: true }));
+ emit(user.username, "payment", payment.get({ plain: true }));
if (order.fee) {
const btc = await getAccount(config.liquid.btcasset, user, transaction);
@@ -323,8 +325,8 @@ const cancel = async (user, id) => {
await btc.increment({ balance: order.fee }, { transaction });
await btc.reload({ transaction });
- emit(user.username, "account", btc.get({ plain: true });
- emit(user.username, "payment", payment.get({ plain: true });
+ emit(user.username, "account", btc.get({ plain: true }));
+ emit(user.username, "payment", payment.get({ plain: true }));
}
broadcast("removeOrder", id);
@@ -342,7 +344,6 @@ app.delete(
await cancel(user, id);
res.send({});
})
-);
app.post(
"/orders",
@@ -358,7 +359,6 @@ app.post(
res.code(500).send(e.message);
}
})
-);
app.get(
"/orders",
@@ -396,7 +396,6 @@ app.get(
res.code(500).send(e.message);
}
})
-);
if (config.maker) {
debug('setup maker account...')