aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2021-12-05 00:52:44 -0800
committerAdam Soltys <[email protected]>2021-12-05 00:52:48 -0800
commit08253d0d17eda59b19b0ab498d417572cb73322c (patch)
tree31117141a10fea42dd2a50dd815b1921340e9d84
parent696a6dfb8c02b584f615a8d31301059fa3f6eb34 (diff)
downloadcoinos-server-08253d0d17eda59b19b0ab498d417572cb73322c.tar.gz
coinos-server-08253d0d17eda59b19b0ab498d417572cb73322c.zip
rename payments global
-rw-r--r--routes/bitcoin/receive.js47
-rw-r--r--routes/liquid/receive.js3
-rw-r--r--routes/lnurl.js6
3 files changed, 28 insertions, 28 deletions
diff --git a/routes/bitcoin/receive.js b/routes/bitcoin/receive.js
index c14e636c..5d8e21e7 100644
--- a/routes/bitcoin/receive.js
+++ b/routes/bitcoin/receive.js
@@ -19,6 +19,7 @@ const network =
];
const queue = {};
+const seen = [];
zmqRawTx.on("message", async (topic, message, sequence) => {
const hex = message.toString("hex");
@@ -26,10 +27,12 @@ zmqRawTx.on("message", async (topic, message, sequence) => {
let hash = reverse(tx.getHash()).toString("hex");
- if (payments.includes(hash)) return;
+ if (seen.includes(hash)) return;
+ seen.push(hash);
+ if (seen.length > 5000) seen.shift();
Promise.all(
- tx.outs.map(async (o) => {
+ tx.outs.map(async o => {
try {
const { value } = o;
@@ -44,25 +47,23 @@ zmqRawTx.on("message", async (topic, message, sequence) => {
Object.keys(addresses).includes(address) &&
!change.includes(address)
) {
- payments.push(hash);
-
let user = await db.User.findOne({
where: {
- username: addresses[address],
- },
+ username: addresses[address]
+ }
});
const invoice = await db.Invoice.findOne({
where: {
address,
user_id: user.id,
- network: "bitcoin",
+ network: "bitcoin"
},
order: [["id", "DESC"]],
include: {
model: db.Account,
- as: "account",
- },
+ as: "account"
+ }
});
if (!invoice) return;
@@ -82,9 +83,9 @@ zmqRawTx.on("message", async (topic, message, sequence) => {
user_id: user.id,
asset: config.liquid.btcasset,
pubkey: null
- }
- });
- }
+ }
+ });
+ }
account.pending += value;
await account.save();
@@ -117,7 +118,7 @@ zmqRawTx.on("message", async (topic, message, sequence) => {
confirmed,
address,
network: "bitcoin",
- invoice_id: invoice.id,
+ invoice_id: invoice.id
});
payment = payment.get({ plain: true });
payment.account = account.get({ plain: true });
@@ -138,13 +139,13 @@ zmqRawTx.on("message", async (topic, message, sequence) => {
zmqRawBlock.on("message", async (topic, message, sequence) => {
const payments = await db.Payment.findAll({
- where: { confirmed: false },
+ where: { confirmed: false }
});
let block = bitcoin.Block.fromHex(message.toString("hex"));
- block.transactions.map((tx) => {
+ block.transactions.map(tx => {
let hash = reverse(tx.getHash()).toString("hex");
- if (payments.find((p) => p.hash === hash)) queue[hash] = 1;
+ if (payments.find(p => p.hash === hash)) queue[hash] = 1;
});
});
@@ -155,25 +156,25 @@ setInterval(async () => {
const hash = arr[i];
let account, address, user, total;
- await db.transaction(async (transaction) => {
+ await db.transaction(async transaction => {
let p = await db.Payment.findOne({
where: { hash, confirmed: 0, received: 1 },
include: [
{
model: db.Account,
- as: "account",
+ as: "account"
},
{
model: db.Invoice,
- as: "invoice",
+ as: "invoice"
},
{
model: db.User,
- as: "user",
- },
+ as: "user"
+ }
],
lock: transaction.LOCK.UPDATE,
- transaction,
+ transaction
});
if (p && p.address) address = p.address;
@@ -222,7 +223,7 @@ setInterval(async () => {
address: c.address,
amount: total - 100,
user,
- limit: total,
+ limit: total
});
}
}
diff --git a/routes/liquid/receive.js b/routes/liquid/receive.js
index 0a72eb00..626cb21a 100644
--- a/routes/liquid/receive.js
+++ b/routes/liquid/receive.js
@@ -75,7 +75,7 @@ zmqRawTx.on("message", async (topic, message, sequence) => {
let unblinded, tx, blinded, txid;
try {
txid = Transaction.fromHex(hex).getId();
- if (seen.includes(txid) || payments.includes(txid)) return;
+ if (seen.includes(txid)) return;
seen.push(txid);
if (seen.length > 5000) seen.shift();
@@ -175,7 +175,6 @@ zmqRawTx.on("message", async (topic, message, sequence) => {
{ transaction }
);
- payments.push(txid);
payment = payment.get({ plain: true });
payment.account = account.get({ plain: true });
diff --git a/routes/lnurl.js b/routes/lnurl.js
index 99e4fad3..71ffe55a 100644
--- a/routes/lnurl.js
+++ b/routes/lnurl.js
@@ -6,7 +6,7 @@ const persist = require("../lib/persist");
logins = persist("data/logins.json");
recipients = persist("data/recipients.json");
-payments = persist("data/payments.json");
+lnurlPayments = persist("data/payments.json");
withdrawals = persist("data/withdrawals.json");
lnurlServer = lnurl.createServer(config.lnurl);
@@ -200,7 +200,7 @@ app.post(
try {
const parts = callback.split("/");
const secret = parts[parts.length - 1];
- payments[secret] = user;
+ lnurlPayments[secret] = user;
if (recipients[secret]) {
url = `${req.protocol}://${req.get("host")}/api/send`;
@@ -291,7 +291,7 @@ lnurlServer.bindToHook(
amount = Math.round(msats / 1000);
const parts = req.originalUrl.split("/");
const secret = parts[parts.length - 1].split("?")[0];
- user = payments[secret];
+ user = lnurlPayments[secret];
if (user) {
let account = await db.Account.findOne({