From 0115f4b85a095b25ac2018d9fdce91010c9961db Mon Sep 17 00:00:00 2001 From: Mothana Date: Mon, 29 Apr 2024 21:32:56 +0400 Subject: [PATCH] service_url --- src/services/main/paymentManager.ts | 23 +++++++++++++++++++++++ src/services/main/settings.ts | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/services/main/paymentManager.ts b/src/services/main/paymentManager.ts index 7e629fb0..729b22a5 100644 --- a/src/services/main/paymentManager.ts +++ b/src/services/main/paymentManager.ts @@ -285,7 +285,21 @@ export default class { return `${this.settings.serviceUrl}/api/guest/lnurl_withdraw/info?k1=${k1}` } + isDefaultServiceUrl(): boolean { + if ( + this.settings.serviceUrl.includes("localhost") + || + this.settings.serviceUrl.includes("127.0.0.1") + ) { + return true + } + return false; + } + async GetLnurlWithdrawLink(ctx: Types.UserContext): Promise { + if(this.isDefaultServiceUrl()) { + throw new Error("Lnurl not enabled. Make sure to set SERVICE_URL env variable") + } const app = await this.storage.applicationStorage.GetApplication(ctx.app_id) const key = await this.storage.paymentStorage.AddUserEphemeralKey(ctx.user_id, 'balanceCheck', app) return { @@ -331,6 +345,9 @@ export default class { } async GetLnurlPayLink(ctx: Types.UserContext): Promise { + if(this.isDefaultServiceUrl()) { + throw new Error("Lnurl not enabled. Make sure to set SERVICE_URL env variable") + } getLogger({})("getting lnurl pay link") const app = await this.storage.applicationStorage.GetApplication(ctx.app_id) const key = await this.storage.paymentStorage.AddUserEphemeralKey(ctx.user_id, 'pay', app) @@ -343,6 +360,9 @@ export default class { } async GetLnurlPayInfoFromUser(userId: string, linkedApplication: Application, baseUrl?: string): Promise { + if(this.isDefaultServiceUrl()) { + throw new Error("Lnurl not enabled. Make sure to set SERVICE_URL env variable") + } 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() @@ -358,6 +378,9 @@ export default class { } async GetLnurlPayInfo(payInfoK1: string): Promise { + if(this.isDefaultServiceUrl()) { + throw new Error("Lnurl not enabled. Make sure to set SERVICE_URL env variable") + } const key = await this.storage.paymentStorage.UseUserEphemeralKey(payInfoK1, 'pay', true) if (!key.linkedApplication) { throw new Error("invalid lnurl request") diff --git a/src/services/main/settings.ts b/src/services/main/settings.ts index e7164967..0a02d632 100644 --- a/src/services/main/settings.ts +++ b/src/services/main/settings.ts @@ -42,7 +42,7 @@ export const LoadMainSettingsFromEnv = (): MainSettings => { outgoingAppUserInvoiceFee: EnvMustBeInteger("OUTGOING_INVOICE_FEE_USER_BPS") / 10000, userToUserFee: EnvMustBeInteger("TX_FEE_INTERNAL_USER_BPS") / 10000, appToUserFee: EnvMustBeInteger("TX_FEE_INTERNAL_ROOT_BPS") / 10000, - serviceUrl: EnvMustBeNonEmptyString("SERVICE_URL"), + serviceUrl: process.env.SERVICE_URL || `http://localhost:${EnvMustBeInteger("PORT")}`, servicePort: EnvMustBeInteger("PORT"), recordPerformance: process.env.RECORD_PERFORMANCE === 'true' || false, skipSanityCheck: process.env.SKIP_SANITY_CHECK === 'true' || false,