From 4bde8faf1b9d91898447bdf2c63b0afd227f978c Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 9 Jul 2021 12:58:14 -0700 Subject: add webhooks to invoices --- routes/bitcoin/receive.js | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'routes/bitcoin') diff --git a/routes/bitcoin/receive.js b/routes/bitcoin/receive.js index ba522aeb..dbc5801b 100644 --- a/routes/bitcoin/receive.js +++ b/routes/bitcoin/receive.js @@ -2,9 +2,6 @@ const reverse = require("buffer-reverse"); const zmq = require("zeromq"); const { Op } = require("sequelize"); const { fromBase58 } = require("bip32"); -const wretch = require("wretch"); -const fetch = require("node-fetch"); -wretch().polyfills({ fetch }); const bitcoin = require("bitcoinjs-lib"); @@ -117,6 +114,7 @@ zmqRawTx.on("message", async (topic, message, sequence) => { emit(user.username, "payment", payment); l.info("bitcoin detected", user.username, value); notify(user, `${value} SAT payment detected`); + await callWebhook(invoice, payment); } } catch (e) { console.log(e); @@ -154,27 +152,19 @@ setInterval(async () => { model: db.Account, as: "account" }, - { - model: db.User, - as: "user" - }, { model: db.Invoice, as: "invoice" + }, + { + model: db.User, + as: "user" } ], lock: transaction.LOCK.UPDATE, transaction }); - if (p.invoice && p.invoice.webhook) { - l.info("calling webhook", p.invoice.webhook); - console.log(await wretch() - .url(p.invoice.webhook) - .post({ oh: "yeah" }) - .json()); - } - if (p && p.address) address = p.address; if (p && p.user) user = p.user; @@ -199,6 +189,7 @@ setInterval(async () => { emit(user.username, "payment", p); l.info("bitcoin confirmed", user.username, p.amount, p.tip); notify(user, `${total} SAT payment confirmed`); + await callWebhook(p.invoice, p); } else { l.warn("couldn't find bitcoin payment", hash); } -- cgit v1.2.3