aboutsummaryrefslogtreecommitdiffstats
path: root/routes/liquid
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2022-09-02 15:06:43 -0700
committerAdam Soltys <[email protected]>2022-09-02 15:06:43 -0700
commitd1cc66d1a02b75f90fbf0c05910777c76228259a (patch)
tree7b93dc6a2fc0ec9d03676d6b4093fedf9733f128 /routes/liquid
parent3161dd7ee95b6c7d70f8341298dd4fab84cda8b0 (diff)
downloadcoinos-server-d1cc66d1a02b75f90fbf0c05910777c76228259a.tar.gz
coinos-server-d1cc66d1a02b75f90fbf0c05910777c76228259a.zip
es6 migration
Diffstat (limited to 'routes/liquid')
-rw-r--r--routes/liquid/broadcast.js5
-rw-r--r--routes/liquid/fee.js6
-rw-r--r--routes/liquid/receive.js29
-rw-r--r--routes/liquid/send.js20
4 files changed, 31 insertions, 29 deletions
diff --git a/routes/liquid/broadcast.js b/routes/liquid/broadcast.js
index 2562effc..1a44cd2b 100644
--- a/routes/liquid/broadcast.js
+++ b/routes/liquid/broadcast.js
@@ -1,3 +1,4 @@
+import { rates } from "../../lib/store.js";
export default async (req, res) => {
try {
const { user } = req;
@@ -21,7 +22,7 @@ export default async (req, res) => {
tip: 0,
account_id: account.id,
user_id: user.id,
- rate: app.get("rates")[user.currency],
+ rate: rates[user.currency],
currency: user.currency,
confirmed: true,
received: false,
@@ -46,7 +47,7 @@ export default async (req, res) => {
res.send(hash);
}
} catch (e) {
- l.error("problem broadcasting liquid transaction", e);
+ err("problem broadcasting liquid transaction", e);
res.status(500).send(e.message);
}
};
diff --git a/routes/liquid/fee.js b/routes/liquid/fee.js
index 0a2c330a..9d8a5bad 100644
--- a/routes/liquid/fee.js
+++ b/routes/liquid/fee.js
@@ -59,7 +59,7 @@ liquidTx = async ({ address, asset, amount, feeRate, replaceable, user }) => {
replaceable
);
- l.info("funding tx for fee estimate", tx);
+ l("funding tx for fee estimate", tx);
tx = await node.fundRawTransaction(tx, params);
@@ -68,7 +68,7 @@ liquidTx = async ({ address, asset, amount, feeRate, replaceable, user }) => {
decoded = await node.decodeRawTransaction(signed.hex);
feeRate = Math.round((tx.fee * SATS * 1000) / decoded.vsize);
- l.info("estimated", asset, feeRate);
+ l("estimated", asset, feeRate);
return { feeRate, tx };
};
@@ -78,7 +78,7 @@ export default async (req, res) => {
let tx = await liquidTx({ ...req.body, user: req.user });
res.send(tx);
} catch (e) {
- l.error("error estimating liquid fee", e.message, e.stack);
+ err("error estimating liquid fee", e.message, e.stack);
return res.status(500).send(e.message);
}
};
diff --git a/routes/liquid/receive.js b/routes/liquid/receive.js
index 8891292e..380fe4f4 100644
--- a/routes/liquid/receive.js
+++ b/routes/liquid/receive.js
@@ -1,15 +1,14 @@
+import { rates } from "../../lib/store.js";
+import { addresses } from "../../lib/store.js";
import { sendLiquid } from "./send.js";
-import { notify } from "../lib/notifications.js";
-import { callWebhook } from "../lib/webhooks.js";
+import { notify } from "../../lib/notifications.js";
+import { callWebhook } from "../../lib/webhooks.js";
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 wretch from 'wretch';
-import fetch from 'node-fetch';
-wretch().polyfills({ fetch });
const network =
networks[
@@ -26,7 +25,7 @@ const getAccount = async (params, transaction) => {
});
if (account) {
- l.info("found account", params, account.asset, account.id);
+ l("found account", params, account.asset, account.id);
return account;
}
@@ -68,7 +67,7 @@ const getAccount = async (params, transaction) => {
});
if (existing) {
- l.info("existing", existing.id);
+ l("existing", existing.id);
({ domain, ticker, precision, name } = existing);
}
}
@@ -105,7 +104,7 @@ zmqRawTx.on("message", async (topic, message, sequence) => {
tx = await lq.decodeRawTransaction(unblinded.hex);
blinded = await lq.decodeRawTransaction(hex);
} catch (e) {
- return l.error("problem decoding liquid tx", e.message);
+ return err("problem decoding liquid tx", e.message);
}
Promise.all(
@@ -173,7 +172,7 @@ zmqRawTx.on("message", async (topic, message, sequence) => {
const currency = invoice ? invoice.currency : user.currency;
const rate = invoice
? invoice.rate
- : app.get("rates")[user.currency];
+ : rates[user.currency];
const tip = invoice ? invoice.tip : 0;
const memo = invoice ? invoice.memo : "";
@@ -201,13 +200,13 @@ zmqRawTx.on("message", async (topic, message, sequence) => {
emit(user.username, "payment", payment);
emit(user.username, "account", payment.account);
- l.info("liquid detected", address, user.username, asset, value);
+ l("liquid detected", address, user.username, asset, value);
notify(user, `${value} SAT payment detected`);
callWebhook(invoice, payment);
});
}
} catch (e) {
- l.error("Problem processing transaction", e.message, e.stack);
+ err("Problem processing transaction", e.message, e.stack);
}
})
);
@@ -357,7 +356,7 @@ setInterval(async () => {
emit(user.username, "account", p.account);
emit(user.username, "payment", p);
- l.info(
+ l(
"liquid confirmed",
user.username,
p.account.asset,
@@ -368,7 +367,7 @@ setInterval(async () => {
notify(user, `${total} SAT payment confirmed`);
callWebhook(p.invoice, p);
} else {
- l.warn("couldn't find liquid payment", hash);
+ warn("couldn't find liquid payment", hash);
}
delete queue[hash];
@@ -376,7 +375,7 @@ setInterval(async () => {
let c = convert[address];
if (address && c && p.account.asset === network.assetHash) {
- l.info(
+ l(
"liquid detected for conversion request",
address,
c.address,
@@ -394,6 +393,6 @@ setInterval(async () => {
}
}
} catch (e) {
- l.error("problem processing queued liquid transaction", e.message, e.stack);
+ err("problem processing queued liquid transaction", e.message, e.stack);
}
}, 1000);
diff --git a/routes/liquid/send.js b/routes/liquid/send.js
index 9529a040..674b93f2 100644
--- a/routes/liquid/send.js
+++ b/routes/liquid/send.js
@@ -1,3 +1,5 @@
+import { rates } from "../../lib/store.js";
+import { addresses } from "../../lib/store.js";
import config from "../../config/index.js";
const btc = config.liquid.btcasset;
const lcad = config.liquid.cadasset;
@@ -9,7 +11,7 @@ import {
export const sendLiquid = async ({ asset, amount, user, address, memo, tx, limit }) => {
try {
- l.info("sending liquid", amount, address);
+ l("sending liquid", amount, address);
if (!tx) {
({ tx } = await liquidTx({
address,
@@ -96,7 +98,7 @@ export const sendLiquid = async ({ asset, amount, user, address, memo, tx, limit
throw new Error("Tx amount exceeds authorized amount");
if (asset !== btc || total) {
- l.info("creating liquid payment", user.username, asset, total, fee);
+ l("creating liquid payment", user.username, asset, total, fee);
let account = await db.Account.findOne({
where: {
@@ -126,7 +128,7 @@ export const sendLiquid = async ({ asset, amount, user, address, memo, tx, limit
if (asset !== btc) conversionFee = 0;
if (total > account.balance) {
- l.warn("amount exceeds balance", {
+ warn("amount exceeds balance", {
total,
fee,
balance: account.balance
@@ -137,7 +139,7 @@ export const sendLiquid = async ({ asset, amount, user, address, memo, tx, limit
}, have ${account.balance}`
);
} else if (total + conversionFee > account.balance) {
- l.warn("amount plus conversion fee exceeds balance", {
+ warn("amount plus conversion fee exceeds balance", {
total,
fee,
conversionFee,
@@ -182,7 +184,7 @@ export const sendLiquid = async ({ asset, amount, user, address, memo, tx, limit
memo: "Liquid conversion fee",
account_id: receiverAccount.id,
user_id: receiverAccount.user_id,
- rate: app.get("rates")[receiverAccount.user.currency],
+ rate: rates[receiverAccount.user.currency],
currency: receiverAccount.user.currency,
confirmed: true,
received: true,
@@ -200,7 +202,7 @@ export const sendLiquid = async ({ asset, amount, user, address, memo, tx, limit
fee,
memo,
user_id: user.id,
- rate: app.get("rates")[user.currency],
+ rate: rates[user.currency],
currency: user.currency,
address,
confirmed: true,
@@ -241,11 +243,11 @@ export const sendLiquid = async ({ asset, amount, user, address, memo, tx, limit
await lq.walletPassphrase(config.liquid.walletpass, 300);
let txid = await lq.sendRawTransaction(signed.hex);
- l.info("sent liquid tx", txid, address);
+ l("sent liquid tx", txid, address);
return main;
} catch (e) {
- l.error("problem sending liquid", e.message);
+ err("problem sending liquid", e.message);
}
};
@@ -255,7 +257,7 @@ export default async (req, res) => {
try {
res.send(await sendLiquid({ ...req.body, user }));
} catch (e) {
- l.error("problem sending liquid", user.username, e.message);
+ err("problem sending liquid", user.username, e.message);
return res.status(500).send(e);
}
};