aboutsummaryrefslogtreecommitdiffstats
path: root/routes
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
parent9bf4080d67d6342624c8f1fb543acab00191f730 (diff)
downloadcoinos-server-0fb703b85d99c888d1df971e7c3562f7918e0ff8.tar.gz
coinos-server-0fb703b85d99c888d1df971e7c3562f7918e0ff8.zip
add webhooks to invoices
Diffstat (limited to 'routes')
-rw-r--r--routes/bitcoin/receive.js33
-rw-r--r--routes/invoices.js2
-rw-r--r--routes/payments.js8
3 files changed, 36 insertions, 7 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);
diff --git a/routes/invoices.js b/routes/invoices.js
index f7682bfe..c188811e 100644
--- a/routes/invoices.js
+++ b/routes/invoices.js
@@ -55,7 +55,7 @@ app.post(
invoice.amount,
invoice.tip,
invoice.currency,
- `${invoice.text.substr(0, 8)}..${invoice.text.substr(-6)}`,
+ invoice.text && `${invoice.text.substr(0, 8)}..${invoice.text.substr(-6)}`,
);
if (!invoice.tip) invoice.tip = 0;
diff --git a/routes/payments.js b/routes/payments.js
index a52ad395..41dfce26 100644
--- a/routes/payments.js
+++ b/routes/payments.js
@@ -17,6 +17,7 @@ ah(async () => {
l.warn("couldn't read exceptions file", e.message);
}
+ try {
(
await db.Invoice.findAll({
include: {
@@ -28,6 +29,9 @@ ah(async () => {
if (address && user) addresses[address] = user.username;
if (unconfidential && user) addresses[unconfidential] = user.username;
});
+ } catch(e) {
+ console.log(e);
+ }
try {
const accounts = await db.Account.findAll({
@@ -51,6 +55,7 @@ ah(async () => {
})
).map((p) => p.hash);
+
setInterval(async () => {
const unconfirmed = (
await db.Payment.findAll({
@@ -129,6 +134,7 @@ ah(async () => {
}
}, 50);
}
+ /*
if (config.liquid) {
lq = new BitcoinCore(config.liquid);
@@ -151,7 +157,6 @@ ah(async () => {
}, 50);
}
-
app.get(
"/payments",
auth,
@@ -194,4 +199,5 @@ ah(async () => {
}
})
);
+*/
})();