Skip to content

Commit

Permalink
Merge pull request #679 from snake-eaterr/service_url
Browse files Browse the repository at this point in the history
service_url
  • Loading branch information
shocknet-justin authored Apr 29, 2024
2 parents c6c34c1 + 670b4a5 commit 7ea25ce
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/services/main/paymentManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Types.LnurlLinkResponse> {
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 {
Expand Down Expand Up @@ -331,6 +345,9 @@ export default class {
}

async GetLnurlPayLink(ctx: Types.UserContext): Promise<Types.LnurlLinkResponse> {
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)
Expand All @@ -343,6 +360,9 @@ export default class {
}

async GetLnurlPayInfoFromUser(userId: string, linkedApplication: Application, baseUrl?: string): Promise<Types.LnurlPayInfoResponse> {
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()
Expand All @@ -358,6 +378,9 @@ export default class {
}

async GetLnurlPayInfo(payInfoK1: string): Promise<Types.LnurlPayInfoResponse> {
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")
Expand Down
2 changes: 1 addition & 1 deletion src/services/main/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 7ea25ce

Please sign in to comment.