From 9670f1e856d0a4c3f7548e69a2b01900fddd6120 Mon Sep 17 00:00:00 2001 From: boufni95 Date: Sun, 1 Sep 2024 17:45:46 +0000 Subject: [PATCH] ln addr meta --- src/services/main/applicationManager.ts | 2 +- src/services/main/paymentManager.ts | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/services/main/applicationManager.ts b/src/services/main/applicationManager.ts index 49f1d280..e2ebad2a 100644 --- a/src/services/main/applicationManager.ts +++ b/src/services/main/applicationManager.ts @@ -226,7 +226,7 @@ export default class { async GetAppUserLNURLInfo(appId: string, req: Types.GetAppUserLNURLInfoRequest): Promise { const app = await this.storage.applicationStorage.GetApplication(appId) const user = await this.storage.applicationStorage.GetApplicationUser(app, req.user_identifier) - return this.paymentManager.GetLnurlPayInfoFromUser(user.user.user_id, app, req.base_url_override) + return this.paymentManager.GetLnurlPayInfoFromUser(user.user.user_id, app, { baseUrl: req.base_url_override }) } async RequestNPubLinkingToken(appId: string, req: Types.RequestNPubLinkingTokenRequest, reset: boolean): Promise { const app = await this.storage.applicationStorage.GetApplication(appId); diff --git a/src/services/main/paymentManager.ts b/src/services/main/paymentManager.ts index 9b7dbe60..31db7fa6 100644 --- a/src/services/main/paymentManager.ts +++ b/src/services/main/paymentManager.ts @@ -40,6 +40,7 @@ interface UserOperationInfo { } export type PendingTx = { type: 'incoming', tx: AddressReceivingTransaction } | { type: 'outgoing', tx: UserTransactionPayment } const defaultLnurlPayMetadata = `[["text/plain", "lnurl pay to Lightning.pub"]]` +const defaultLnAddressMetadata = (id: string) => `[["text/plain", "lnurl pay to Lightning.pub"],["text/identifier", "${id}"]]` const confInOne = 1000 * 1000 const confInTwo = 100 * 1000 * 1000 export default class { @@ -135,7 +136,7 @@ export default class { //}) return } - console.log({p}) + console.log({ p }) const paymentRes = await this.lnd.GetPayment(p.paymentIndex) const payment = paymentRes.payments[0] if (!payment || Number(payment.paymentIndex) !== p.paymentIndex) { @@ -337,7 +338,7 @@ export default class { const pendingPayment = await this.storage.txQueue.PushToQueue({ dbTx: true, description: "payment started", exec: async tx => { await this.storage.userStorage.DecrementUserBalance(userId, totalAmountToDecrement + routingFeeLimit, invoice, tx) - return await this.storage.paymentStorage.AddPendingExternalPayment(userId, invoice, { payAmount, serviceFee, networkFee: routingFeeLimit }, linkedApplication, provider,tx) + return await this.storage.paymentStorage.AddPendingExternalPayment(userId, invoice, { payAmount, serviceFee, networkFee: routingFeeLimit }, linkedApplication, provider, tx) } }) this.log("ready to pay") @@ -513,10 +514,11 @@ export default class { } } - async GetLnurlPayInfoFromUser(userId: string, linkedApplication: Application, baseUrl?: string): Promise { + async GetLnurlPayInfoFromUser(userId: string, linkedApplication: Application, opts: { baseUrl?: string, metadata?: string } = {}): Promise { if (this.isDefaultServiceUrl()) { throw new Error("Lnurl not enabled. Make sure to set SERVICE_URL env variable") } + const { baseUrl, metadata } = opts const payK1 = await this.storage.paymentStorage.AddUserEphemeralKey(userId, 'pay', linkedApplication) const url = baseUrl ? baseUrl : `${this.settings.serviceUrl}/api/guest/lnurl_pay/handle` const { remote } = await this.lnd.ChannelBalance() @@ -525,7 +527,7 @@ export default class { callback: `${url}?k1=${payK1.key}`, maxSendable: remote * 1000, minSendable: 10000, - metadata: defaultLnurlPayMetadata, + metadata: metadata ? metadata : defaultLnurlPayMetadata, allowsNostr: !!linkedApplication.nostr_public_key, nostrPubkey: linkedApplication.nostr_public_key || "" } @@ -634,7 +636,7 @@ export default class { if (!linkedUser) { throw new Error("this address is not linked to any user") } - return this.GetLnurlPayInfoFromUser(linkedUser.user.user_id, linkedUser.application) + return this.GetLnurlPayInfoFromUser(linkedUser.user.user_id, linkedUser.application, { metadata: defaultLnAddressMetadata(addressName) }) } async OpenChannel(userId: string, req: Types.OpenChannelRequest): Promise { throw new Error("WIP") }