aboutsummaryrefslogtreecommitdiffstats
path: root/routes/liquid
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2020-03-28 23:13:13 -0700
committerAdam Soltys <[email protected]>2020-03-28 23:13:13 -0700
commita0422300e2b13896634eda12930959bc64ba7dc9 (patch)
tree481915dc9e311d7dfc31d0b237b2c06ad5fa26a5 /routes/liquid
parent5142c8cfcffd59d04ec18e67183a1866324d9209 (diff)
downloadcoinos-server-a0422300e2b13896634eda12930959bc64ba7dc9.tar.gz
coinos-server-a0422300e2b13896634eda12930959bc64ba7dc9.zip
handle tips and invoices better
Diffstat (limited to 'routes/liquid')
-rw-r--r--routes/liquid/receive.js33
-rw-r--r--routes/liquid/send.js2
2 files changed, 17 insertions, 18 deletions
diff --git a/routes/liquid/receive.js b/routes/liquid/receive.js
index 6a7e53b8..2b459af3 100644
--- a/routes/liquid/receive.js
+++ b/routes/liquid/receive.js
@@ -11,7 +11,7 @@ const zmqRawTx = zmq.socket("sub");
zmqRawTx.connect("tcp://127.0.0.1:18603");
zmqRawTx.subscribe("rawtx");
-let NETWORK = bitcoin.networks[config.bitcoin.network === "mainnet" ? "bitcoin" : config.bitcoin.network];
+const asset = 'LBTC';
zmqRawTx.on("message", async (topic, message, sequence) => {
const hex = message.toString("hex");
@@ -35,20 +35,17 @@ zmqRawTx.on("message", async (topic, message, sequence) => {
}
});
- let invoices = await db.Payment.findAll({
- limit: 1,
+ const invoice = await db.Invoice.findOne({
where: {
- address,
- received: null,
- amount: {
- [Op.gt]: 0
- }
+ user_id: user.id,
+ asset,
},
- order: [["id", "DESC"]]
+ order: [ [ 'id', 'DESC' ]]
});
- let tip = null;
- if (invoices.length) tip = invoices[0].tip;
+ const currency = invoice ? invoice.currency : user.currency;
+ const rate = invoice ? invoice.rate : app.get("rates")[user.currency];
+ const tip = invoice ? invoice.tip : null;
let confirmed = 0;
@@ -64,14 +61,14 @@ zmqRawTx.on("message", async (topic, message, sequence) => {
const payment = await db.Payment.create({
user_id: user.id,
hash: blinded.txid,
- amount: value,
- currency: user.currency,
- rate: app.get("rates")[user.currency],
+ amount: value - tip,
+ currency,
+ rate,
received: true,
tip,
confirmed,
address,
- asset: 'LBTC',
+ asset,
});
payments.push(blinded.txid);
@@ -114,9 +111,9 @@ setInterval(async () => {
p.confirmed = 1;
let user = await p.getUser();
- user.balance += p.amount;
- user.pending -= Math.min(user.pending, p.amount);
- l.info("liquid confirmed", user.username, p.amount);
+ user.balance += p.amount + p.tip;
+ user.pending -= Math.min(user.pending, p.amount + p.tip);
+ l.info("liquid confirmed", user.username, p.amount, p.tip);
emit(user.username, "user", user);
await user.save();
diff --git a/routes/liquid/send.js b/routes/liquid/send.js
index eb369a01..c657ae30 100644
--- a/routes/liquid/send.js
+++ b/routes/liquid/send.js
@@ -34,6 +34,8 @@ module.exports = async (req, res) => {
total = total - change;
let amount = total - fee;
+ l.info("attempting liquid payment", user.username, amount, fee);
+
try {
await db.transaction(async transaction => {
let { balance } = await db.User.findOne({