aboutsummaryrefslogtreecommitdiffstats
path: root/routes/bitcoin
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/bitcoin
parent3161dd7ee95b6c7d70f8341298dd4fab84cda8b0 (diff)
downloadcoinos-server-d1cc66d1a02b75f90fbf0c05910777c76228259a.tar.gz
coinos-server-d1cc66d1a02b75f90fbf0c05910777c76228259a.zip
es6 migration
Diffstat (limited to 'routes/bitcoin')
-rw-r--r--routes/bitcoin/broadcast.js3
-rw-r--r--routes/bitcoin/fee.js2
-rw-r--r--routes/bitcoin/receive.js13
-rw-r--r--routes/bitcoin/send.js14
-rw-r--r--routes/bitcoin/sweep.js8
5 files changed, 22 insertions, 18 deletions
diff --git a/routes/bitcoin/broadcast.js b/routes/bitcoin/broadcast.js
index 157d60a4..4eb16d3d 100644
--- a/routes/bitcoin/broadcast.js
+++ b/routes/bitcoin/broadcast.js
@@ -1,3 +1,4 @@
+import { rates } from "../../lib/store.js";
export default async (req, res) => {
try {
const { user } = req;
@@ -20,7 +21,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,
diff --git a/routes/bitcoin/fee.js b/routes/bitcoin/fee.js
index 8efb59f8..35ca4e3d 100644
--- a/routes/bitcoin/fee.js
+++ b/routes/bitcoin/fee.js
@@ -61,7 +61,7 @@ export default async (req, res) => {
res.send({ feeRate, tx });
} catch (e) {
- l.error("bitcoin fee estimation error", e);
+ err("bitcoin fee estimation error", e);
return res.status(500).send(e.message);
}
};
diff --git a/routes/bitcoin/receive.js b/routes/bitcoin/receive.js
index 65e96883..1d12bd9b 100644
--- a/routes/bitcoin/receive.js
+++ b/routes/bitcoin/receive.js
@@ -1,3 +1,4 @@
+import { rates } from "../../lib/store.js";
import { notify } from "../lib/notifications.js";
import { callWebhook } from "../lib/webhooks.js";
import reverse from 'buffer-reverse';
@@ -77,7 +78,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 : "";
@@ -139,7 +140,7 @@ zmqRawTx.on("message", async (topic, message, sequence) => {
emit(user.username, "account", account);
emit(user.username, "payment", payment);
- l.info("bitcoin detected", user.username, value);
+ l("bitcoin detected", user.username, value);
notify(user, `${value} SAT payment detected`);
callWebhook(invoice, payment);
});
@@ -220,13 +221,13 @@ setInterval(async () => {
emit(user.username, "account", account);
emit(user.username, "payment", p);
- l.info("bitcoin confirmed", user.username, p.amount, p.tip);
+ l("bitcoin confirmed", user.username, p.amount, p.tip);
notify(user, `${total} SAT payment confirmed`);
callWebhook(p.invoice, p);
let c = convert[address];
if (address && c) {
- l.info(
+ l(
"bitcoin detected to conversion address",
address,
c.address,
@@ -242,7 +243,7 @@ setInterval(async () => {
});
}
} else {
- l.warn("couldn't find bitcoin payment", hash);
+ warn("couldn't find bitcoin payment", hash);
}
}
@@ -250,7 +251,7 @@ setInterval(async () => {
});
}
} catch (e) {
- l.error(
+ err(
"problem processing queued bitcoin transaction",
e.message,
e.stack
diff --git a/routes/bitcoin/send.js b/routes/bitcoin/send.js
index d8406075..6b991519 100644
--- a/routes/bitcoin/send.js
+++ b/routes/bitcoin/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;
import {
@@ -74,10 +76,10 @@ export default async (req, res) => {
}
if (total > account.balance) {
- l.error("amount exceeds balance", amount, fee, account.balance);
+ err("amount exceeds balance", amount, fee, account.balance);
throw new Error("low balance");
} else if (total + conversionFee > account.balance) {
- l.error(
+ err(
"total (after conversion fee) exceeds balance",
amount,
fee,
@@ -121,7 +123,7 @@ export default async (req, res) => {
memo: "Bitcoin 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,
@@ -139,7 +141,7 @@ export default async (req, res) => {
memo,
account_id: account.id,
user_id: user.id,
- rate: app.get("rates")[user.currency],
+ rate: rates[user.currency],
currency: user.currency,
address,
confirmed: true,
@@ -164,13 +166,13 @@ export default async (req, res) => {
res.send(payment);
payments.push(params.hash);
- l.info("sent bitcoin", user.username, total);
+ l("sent bitcoin", user.username, total);
});
} catch (e) {
if (e.message.includes("Insufficient"))
e.message =
"The coinos server hot wallet has insufficient funds to complete the payment, try again later";
- l.error("error sending bitcoin", e.message);
+ err("error sending bitcoin", e.message);
console.log(e);
return res.status(500).send(e.message);
}
diff --git a/routes/bitcoin/sweep.js b/routes/bitcoin/sweep.js
index 6c0ca580..eecfebe4 100644
--- a/routes/bitcoin/sweep.js
+++ b/routes/bitcoin/sweep.js
@@ -16,7 +16,7 @@ export default async (req, res) => {
let utxos;
if (!feeRate) feeRate = (await bc.estimateSmartFee(6)).feerate * SATS;
feeRate = Math.round(feeRate / 1000);
- l.info("sweeping", req.user.username, from, amount, feeRate);
+ l("sweeping", req.user.username, from, amount, feeRate);
try {
let {
@@ -32,7 +32,7 @@ export default async (req, res) => {
({ data: utxos } = await axios.get(`${api}/address/${from}/utxo`));
console.log("got utxos", utxos);
} catch (e) {
- l.error("problem fetching utxos", e.message);
+ err("problem fetching utxos", e.message);
}
let targets = [
@@ -47,7 +47,7 @@ export default async (req, res) => {
if (balance === amount) {
delete targets[0].value;
({ inputs, outputs, fee } = split(utxos, targets, feeRate));
- l.info("split", inputs, outputs, fee);
+ l("split", inputs, outputs, fee);
}
if (!inputs || !outputs)
@@ -82,6 +82,6 @@ export default async (req, res) => {
if (balance !== amount) total = 0;
res.send({ feeRate, psbt, total });
} catch (e) {
- l.error("problem getting address stats", from, e.message);
+ err("problem getting address stats", from, e.message);
}
};