aboutsummaryrefslogtreecommitdiffstats
path: root/routes/bitcoin
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2021-02-20 23:02:56 -0800
committerAdam Soltys <[email protected]>2021-02-20 23:02:56 -0800
commitd3e0bb7ef5bd1dac383e1df34a312cbc65907cda (patch)
tree64dffaaad65c4eb101d1ca5f40f20a28fb03bea6 /routes/bitcoin
parentc2af135c0459fa416be034e38914c879c620b990 (diff)
downloadcoinos-server-d3e0bb7ef5bd1dac383e1df34a312cbc65907cda.tar.gz
coinos-server-d3e0bb7ef5bd1dac383e1df34a312cbc65907cda.zip
btc to liquid conversion
Diffstat (limited to 'routes/bitcoin')
-rw-r--r--routes/bitcoin/receive.js34
1 files changed, 25 insertions, 9 deletions
diff --git a/routes/bitcoin/receive.js b/routes/bitcoin/receive.js
index 30a3852a..ccaabc06 100644
--- a/routes/bitcoin/receive.js
+++ b/routes/bitcoin/receive.js
@@ -56,8 +56,8 @@ zmqRawTx.on("message", async (topic, message, sequence) => {
order: [["id", "DESC"]],
include: {
model: db.Account,
- as: "account",
- },
+ as: "account"
+ }
});
if (!invoice) return;
@@ -136,6 +136,7 @@ setInterval(async () => {
for (let i = 0; i < arr.length; i++) {
const hash = arr[i];
+ let account, address, user;
await db.transaction(async transaction => {
let p = await db.Payment.findOne({
where: { hash, confirmed: 0, received: 1 },
@@ -153,24 +154,25 @@ setInterval(async () => {
transaction
});
- const { user } = p;
+ ({ account, address, user } = p);
if (p && p.account) {
let total = p.amount + p.tip;
p.confirmed = 1;
- await p.account.save({ transaction });
- await p.account.increment({ balance: total }, { transaction });
- await p.account.decrement(
- { pending: Math.min(p.account.pending, total) },
+ await account.save({ transaction });
+
+ await account.increment({ balance: total }, { transaction });
+ await account.decrement(
+ { pending: Math.min(account.pending, total) },
{ transaction }
);
- await p.account.reload({ transaction });
+ await account.reload({ transaction });
await p.save({ transaction });
p = p.get({ plain: true });
- emit(user.username, "account", p.account);
+ emit(user.username, "account", account);
emit(user.username, "payment", p);
l.info("bitcoin confirmed", user.username, p.amount, p.tip);
notify(user, `${total} SAT payment confirmed`);
@@ -180,6 +182,20 @@ setInterval(async () => {
delete queue[hash];
});
+
+ let c = convert[address];
+ if (c) {
+ let { tx } = c;
+ user.account = account;
+
+ delete queue[hash];
+
+ await sendLiquid({
+ address,
+ user,
+ tx
+ });
+ }
}
} catch (e) {
l.error("problem processing queued bitcoin transaction", e.message);