From cb38551cc4ec392911d18dda9b5a9fe97087ad61 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 28 Dec 2023 22:50:56 -0800 Subject: liquid --- lib/invoices.js | 5 +++++ lib/migrate.js | 2 +- lib/payments.js | 13 ++++++++----- 3 files changed, 14 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/invoices.js b/lib/invoices.js index b5718e23..8023bdbb 100644 --- a/lib/invoices.js +++ b/lib/invoices.js @@ -86,6 +86,11 @@ export let generate = async ({ invoice, user, sender, memo }) => { if (!user.username === 'lightningins') l(type, "invoice", user.username, amount); + if (type === "liquid") { + let { unconfidential } = await lq.getAddressInfo(hash); + await s(`invoice:${unconfidential}`, id); + } + await s(`invoice:${hash}`, id); await s(`invoice:${id}`, invoice); await db.lPush(`${user.id}:invoices`, id); diff --git a/lib/migrate.js b/lib/migrate.js index 81743934..b2c094e3 100644 --- a/lib/migrate.js +++ b/lib/migrate.js @@ -16,7 +16,7 @@ async function migrate(id) { .set(`user:${user.username}`, id) .set(`user:${user.pubkey}`, id) .set(`user:${id}`, JSON.stringify(user)) - .set(`${id}:contacts`, await archive.get(`${id}:contacts`) || '[]') + .set(`${id}:contacts`, (await archive.get(`${id}:contacts`)) || "[]") .set( `credit:bitcoin:${id}`, (await archive.get(`credit:bitcoin:${id}`)) || 0, diff --git a/lib/payments.js b/lib/payments.js index e0aff192..03daf93e 100644 --- a/lib/payments.js +++ b/lib/payments.js @@ -5,7 +5,7 @@ import { v4 } from "uuid"; import { notify } from "$lib/notifications"; import { db, g, s, t } from "$lib/db"; import { l, err, warn } from "$lib/logging"; -import { fail, wait, SATS } from "$lib/utils"; +import { fail, sleep, wait, SATS } from "$lib/utils"; import { callWebhook } from "$lib/webhooks"; import got from "got"; import { spawn } from "child_process"; @@ -61,7 +61,7 @@ export let debit = async ({ if (!amount || amount < 0) fail("Amount must be greater than zero"); - let ourfee = [types.bitcoin, types.lightning].includes(type) + let ourfee = [types.bitcoin, types.liquid, types.lightning].includes(type) ? Math.round(amount * config.fee) : 0; @@ -128,6 +128,9 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => { let rate = store.rates[currency]; + if (!rate) await sleep(1000); + rate = store.rates[currency]; + let equivalentRate = invoice.rate * (store.rates[currency] / store.rates[invoice.currency]); @@ -153,11 +156,11 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => { created: Date.now(), }; - if (type === types.bitcoin) invoice.pending += amount; + if ([types.bitcoin, types.liquid].includes(type)) invoice.pending += amount; else invoice.received += amount; let balance = "balance"; - if (type === types.bitcoin) { + if ([types.bitcoin, types.liquid].includes(type)) { let [txid, vout] = ref.split(":").slice(-2); p.confirmed = false; balance = "pending"; @@ -168,7 +171,7 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => { let m = await db.multi(); - if ([types.bitcoin, types.lightning].includes(type)) + if ([types.bitcoin, types.liquid, types.lightning].includes(type)) m.incrBy(`credit:${type}:${uid}`, Math.round(amount * config.fee)); m.set(`invoice:${iid}`, JSON.stringify(invoice)) -- cgit v1.2.3