From d850e1c2f616ac5707a1d1be015b0bcdf08bf308 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 15 Jan 2025 16:32:23 -0800 Subject: default to blech32 for liquid --- lib/invoices.ts | 6 +++++- routes/invoices.ts | 11 ++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/invoices.ts b/lib/invoices.ts index b158592c..d121353c 100644 --- a/lib/invoices.ts +++ b/lib/invoices.ts @@ -13,7 +13,7 @@ const lq = rpc(config.liquid); export const generate = async ({ invoice, user }) => { let { - address_type = "bech32", + address_type, bolt11, aid, currency, @@ -32,6 +32,7 @@ export const generate = async ({ invoice, user }) => { secret, } = invoice; + amount = parseInt(amount || 0); tip = parseInt(tip) || null; @@ -101,9 +102,11 @@ export const generate = async ({ invoice, user }) => { await s(`invoice:${r.offer_id}`, id); } else if (type === types.bitcoin) { + address_type ||= "bech32" hash = await bc.getNewAddress({ address_type }); text = bip21(hash, invoice); } else if (type === types.liquid) { + address_type ||= "blech32" hash = await lq.getNewAddress({ address_type }); text = bip21(hash, invoice); } else if (type === types.internal) { @@ -118,6 +121,7 @@ export const generate = async ({ invoice, user }) => { invoice = { amount, aid, + address_type, created: Date.now(), currency, hash, diff --git a/routes/invoices.ts b/routes/invoices.ts index a545459a..6f24e990 100644 --- a/routes/invoices.ts +++ b/routes/invoices.ts @@ -2,7 +2,7 @@ import config from "$config"; import { db, g } from "$lib/db"; import { generate } from "$lib/invoices"; import { err } from "$lib/logging"; -import { bail, getInvoice, pick } from "$lib/utils"; +import { bail, fields, getInvoice, getUser } from "$lib/utils"; import rpc from "@coinos/rpc"; export default { @@ -15,14 +15,7 @@ export default { if (invoice) { invoice.secret = undefined; - invoice.user = pick(await g(`user:${invoice.uid}`), [ - "id", - "picture", - "banner", - "currency", - "username", - "pubkey", - ]); + invoice.user = await getUser(invoice.uid, fields); invoice.items ||= []; } -- cgit v1.2.3