aboutsummaryrefslogtreecommitdiffstats
path: root/routes/bitcoin
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2021-06-29 10:28:58 -0700
committerAdam Soltys <[email protected]>2021-07-07 12:42:19 -0700
commit0fb703b85d99c888d1df971e7c3562f7918e0ff8 (patch)
tree2f167df25b172c3b7166952444e39e7f582e93c4 /routes/bitcoin
parent9bf4080d67d6342624c8f1fb543acab00191f730 (diff)
downloadcoinos-server-0fb703b85d99c888d1df971e7c3562f7918e0ff8.tar.gz
coinos-server-0fb703b85d99c888d1df971e7c3562f7918e0ff8.zip
add webhooks to invoices
Diffstat (limited to 'routes/bitcoin')
-rw-r--r--routes/bitcoin/receive.js33
1 files changed, 28 insertions, 5 deletions
diff --git a/routes/bitcoin/receive.js b/routes/bitcoin/receive.js
index 6bf38a9e..ba522aeb 100644
--- a/routes/bitcoin/receive.js
+++ b/routes/bitcoin/receive.js
@@ -2,6 +2,9 @@ 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");
@@ -84,7 +87,6 @@ zmqRawTx.on("message", async (topic, message, sequence) => {
for (let i = 0; i < tx.ins.length; i++) {
let { hash, index } = tx.ins[i];
hash = reverse(hash).toString("hex");
- console.log(hash);
let hex = await bc.getRawTransaction(hash);
let inputTx = bitcoin.Transaction.fromHex(hex);
totalInputs += inputTx.outs[index].value;
@@ -104,7 +106,8 @@ zmqRawTx.on("message", async (topic, message, sequence) => {
tip,
confirmed,
address,
- network: "bitcoin"
+ network: "bitcoin",
+ invoice_id: invoice.id
});
payment = payment.get({ plain: true });
payment.account = account.get({ plain: true });
@@ -154,13 +157,24 @@ setInterval(async () => {
{
model: db.User,
as: "user"
+ },
+ {
+ model: db.Invoice,
+ as: "invoice"
}
],
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;
@@ -194,7 +208,12 @@ setInterval(async () => {
let c = convert[address];
if (address && c) {
- l.info("bitcoin detected to conversion address", address, c.address, user.username);
+ l.info(
+ "bitcoin detected to conversion address",
+ address,
+ c.address,
+ user.username
+ );
user.account = account;
await sendLiquid({
@@ -206,6 +225,10 @@ setInterval(async () => {
}
}
} catch (e) {
- l.error("problem processing queued bitcoin transaction", e.message, e.stack);
+ l.error(
+ "problem processing queued bitcoin transaction",
+ e.message,
+ e.stack
+ );
}
}, 1000);