aboutsummaryrefslogtreecommitdiffstats
path: root/routes/bitcoin
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2020-04-27 21:42:10 -0700
committerAdam Soltys <[email protected]>2020-04-28 22:33:02 -0700
commit994dd93f6c45c590ae59a699cbf425d96518da1e (patch)
tree89b2a980fbad1e964e91ca3750b89051ddfb32f0 /routes/bitcoin
parente166ab2c743e4c66eacb51c6484711c5965dd090 (diff)
downloadcoinos-server-994dd93f6c45c590ae59a699cbf425d96518da1e.tar.gz
coinos-server-994dd93f6c45c590ae59a699cbf425d96518da1e.zip
fix lightning payments
Diffstat (limited to 'routes/bitcoin')
-rw-r--r--routes/bitcoin/receive.js26
-rw-r--r--routes/bitcoin/send.js10
2 files changed, 22 insertions, 14 deletions
diff --git a/routes/bitcoin/receive.js b/routes/bitcoin/receive.js
index 74afb4fb..acc80b09 100644
--- a/routes/bitcoin/receive.js
+++ b/routes/bitcoin/receive.js
@@ -47,7 +47,7 @@ zmqRawTx.on("message", async (topic, message, sequence) => {
const invoice = await db.Invoice.findOne({
where: {
user_id: user.id,
- network: 'BTC',
+ network: "BTC"
},
order: [["id", "DESC"]]
});
@@ -86,7 +86,7 @@ zmqRawTx.on("message", async (topic, message, sequence) => {
tip,
confirmed,
address,
- network: 'BTC'
+ network: "BTC"
});
l.info("bitcoin detected", user.username, o.value);
@@ -125,16 +125,20 @@ setInterval(async () => {
}
});
- p.confirmed = 1;
- p.account.balance += p.amount + p.tip;
- p.account.pending -= Math.min(p.account.pending, p.amount + p.tip);
+ if (p) {
+ p.confirmed = 1;
+ p.account.balance += p.amount + p.tip;
+ p.account.pending -= Math.min(p.account.pending, p.amount + p.tip);
- await p.account.save();
- await p.save();
+ await p.account.save();
+ await p.save();
- let user = await getUserById(p.user_id);
- emit(user.username, "user", user);
- l.info("bitcoin confirmed", user.username, p.amount, p.tip);
- delete queue[hash];
+ let user = await getUserById(p.user_id);
+ emit(user.username, "user", user);
+ l.info("bitcoin confirmed", user.username, p.amount, p.tip);
+ delete queue[hash];
+ } else {
+ l.warn("Couldn't find payment", hash);
+ }
}
}, 1000);
diff --git a/routes/bitcoin/send.js b/routes/bitcoin/send.js
index bb0cf97b..e7cba943 100644
--- a/routes/bitcoin/send.js
+++ b/routes/bitcoin/send.js
@@ -66,7 +66,7 @@ module.exports = async (req, res) => {
await db.transaction(async transaction => {
await user.save({ transaction });
- emit(user.username, "user", user);
+ user = await getUser(user.username);
const payment = await db.Payment.create(
{
@@ -85,12 +85,16 @@ module.exports = async (req, res) => {
{ transaction }
);
- l.info("sent bitcoin", user.username, total);
+ user = await getUser(user.username);
emit(user.username, "payment", payment);
+ emit(user.username, "user", user);
+
res.send(payment);
+
+ l.info("sent bitcoin", user.username, total);
});
} catch (e) {
- l.error("error sending bitcoin", e);
+ l.error("error sending bitcoin", e.message);
return res.status(500).send(e.message);
}
};