aboutsummaryrefslogtreecommitdiffstats
path: root/routes/lightning
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2021-02-19 21:46:21 -0800
committerAdam Soltys <[email protected]>2021-02-19 21:46:21 -0800
commitfb2a1a9f7262c58636b62fe1eee1b95e88a481c8 (patch)
treefc05ad9ac87f402ec48e08d8792e44df72631d23 /routes/lightning
parent035afbbbc1c00f15d3956dbd21adb3a9c82c223e (diff)
downloadcoinos-server-fb2a1a9f7262c58636b62fe1eee1b95e88a481c8.tar.gz
coinos-server-fb2a1a9f7262c58636b62fe1eee1b95e88a481c8.zip
instant lightning->liquid conversion
Diffstat (limited to 'routes/lightning')
-rw-r--r--routes/lightning/invoice.js3
-rw-r--r--routes/lightning/receive.js45
2 files changed, 35 insertions, 13 deletions
diff --git a/routes/lightning/invoice.js b/routes/lightning/invoice.js
index 701ed3c2..140a3002 100644
--- a/routes/lightning/invoice.js
+++ b/routes/lightning/invoice.js
@@ -1,5 +1,6 @@
module.exports = ah(async (req, res) => {
- const { amount, memo, tip } = req.body;
+ let { amount, memo, tip } = req.body;
+ if (!tip) tip = 0;
try {
if (config.lna.clightning) {
diff --git a/routes/lightning/receive.js b/routes/lightning/receive.js
index 0c8d6557..2144470f 100644
--- a/routes/lightning/receive.js
+++ b/routes/lightning/receive.js
@@ -1,12 +1,12 @@
-const handlePayment = async (msg) => {
+const handlePayment = async msg => {
try {
- await db.transaction(async (transaction) => {
+ await db.transaction(async transaction => {
if (!msg.settled) return;
const invoice = await db.Invoice.findOne({
where: {
- text: msg.payment_request,
- },
+ text: msg.payment_request
+ }
});
if (!invoice)
@@ -22,17 +22,38 @@ const handlePayment = async (msg) => {
where: {
user_id,
asset: config.liquid.btcasset,
+ pubkey: null
},
include: {
model: db.User,
- as: "user",
+ as: "user"
},
lock: transaction.LOCK.UPDATE,
- transaction,
+ transaction
});
const { user } = account;
+ let address = convert[msg.payment_request];
+ if (address) {
+ user.account = account;
+
+ let { tx } = await liquidTx({
+ address,
+ asset: config.liquid.btcasset,
+ amount,
+ feeRate: 1000,
+ replaceable: true,
+ user
+ });
+
+ return sendLiquid({
+ address,
+ user,
+ tx
+ });
+ }
+
let preimage = msg.r_preimage.toString("hex");
let payment = await db.Payment.create(
@@ -48,7 +69,7 @@ const handlePayment = async (msg) => {
received: true,
confirmed: true,
network: "lightning",
- tip,
+ tip
},
{ transaction }
);
@@ -82,14 +103,14 @@ const handlePayment = async (msg) => {
};
if (config.lna.clightning) {
- const poll = async (ln) => {
- const wait = async (i) => {
+ const poll = async ln => {
+ const wait = async i => {
const {
bolt11: payment_request,
pay_index,
status,
msatoshi_received,
- payment_preimage: r_preimage,
+ payment_preimage: r_preimage
} = await ln.waitanyinvoice(i);
let settled = status === "paid";
@@ -99,13 +120,13 @@ if (config.lna.clightning) {
payment_request,
settled,
amt_paid_sat,
- r_preimage,
+ r_preimage
});
wait(pay_index);
};
const { invoices } = await ln.listinvoices();
- wait(Math.max(...invoices.map((i) => i.pay_index).filter((n) => n)));
+ wait(Math.max(...invoices.map(i => i.pay_index).filter(n => n)));
};
poll(lna);