lnyrl proxy
This commit is contained in:
parent
6ae03e520c
commit
5278dda7d9
5 changed files with 2009 additions and 1969 deletions
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -94,6 +94,7 @@ message SendAppUserToAppPaymentRequest {
|
||||||
|
|
||||||
message GetAppUserLNURLInfoRequest {
|
message GetAppUserLNURLInfoRequest {
|
||||||
string user_identifier = 1;
|
string user_identifier = 1;
|
||||||
|
string base_url_override = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message SetMockAppUserBalanceRequest {
|
message SetMockAppUserBalanceRequest {
|
||||||
|
|
|
||||||
|
|
@ -181,11 +181,12 @@ export default class {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async GetLnurlPayInfoFromUser(userId: string): Promise<Types.LnurlPayInfoResponse> {
|
async GetLnurlPayInfoFromUser(userId: string, baseUrl?: string): Promise<Types.LnurlPayInfoResponse> {
|
||||||
const payK1 = await this.storage.paymentStorage.AddUserEphemeralKey(userId, 'pay')
|
const payK1 = await this.storage.paymentStorage.AddUserEphemeralKey(userId, 'pay')
|
||||||
|
const url = baseUrl ? baseUrl : `${this.settings.serviceUrl}/api/guest/lnurl_pay/handle`
|
||||||
return {
|
return {
|
||||||
tag: 'payRequest',
|
tag: 'payRequest',
|
||||||
callback: `${this.settings.serviceUrl}/api/guest/lnurl_pay/handle?k1=${payK1.key}`,
|
callback: `${url}?k1=${payK1.key}`,
|
||||||
maxSendable: 10000000,
|
maxSendable: 10000000,
|
||||||
minSendable: 0,
|
minSendable: 0,
|
||||||
metadata: defaultLnurlPayMetadata
|
metadata: defaultLnurlPayMetadata
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ export type StorageSettings = {
|
||||||
export const LoadStorageSettingsFromEnv = (test = false): StorageSettings => {
|
export const LoadStorageSettingsFromEnv = (test = false): StorageSettings => {
|
||||||
return { dbSettings: LoadDbSettingsFromEnv(test) }
|
return { dbSettings: LoadDbSettingsFromEnv(test) }
|
||||||
}
|
}
|
||||||
|
type TX = (entityManager: EntityManager) => Promise<void>
|
||||||
|
|
||||||
export default class {
|
export default class {
|
||||||
DB: DataSource | EntityManager
|
DB: DataSource | EntityManager
|
||||||
|
|
@ -30,6 +31,7 @@ export default class {
|
||||||
userStorage: UserStorage
|
userStorage: UserStorage
|
||||||
paymentStorage: PaymentStorage
|
paymentStorage: PaymentStorage
|
||||||
pendingTx: boolean
|
pendingTx: boolean
|
||||||
|
transactionsQueue: { exec: TX, res: () => void, rej: (message: string) => void }[] = []
|
||||||
constructor(settings: StorageSettings) {
|
constructor(settings: StorageSettings) {
|
||||||
this.settings = settings
|
this.settings = settings
|
||||||
}
|
}
|
||||||
|
|
@ -40,7 +42,32 @@ export default class {
|
||||||
this.applicationStorage = new ApplicationStorage(this.DB, this.userStorage)
|
this.applicationStorage = new ApplicationStorage(this.DB, this.userStorage)
|
||||||
this.paymentStorage = new PaymentStorage(this.DB, this.userStorage)
|
this.paymentStorage = new PaymentStorage(this.DB, this.userStorage)
|
||||||
}
|
}
|
||||||
StartTransaction(exec: (entityManager: EntityManager) => Promise<void>) {
|
|
||||||
|
StartTransaction(exec: TX) {
|
||||||
|
if (!this.pendingTx) {
|
||||||
|
return this.doTransaction(exec)
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Promise<void>((res, rej) => {
|
||||||
|
this.transactionsQueue.push({ exec, res, rej })
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async ExecNextInQueue() {
|
||||||
|
this.pendingTx = false
|
||||||
|
const next = this.transactionsQueue.pop()
|
||||||
|
if (!next) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await this.doTransaction(next.exec)
|
||||||
|
next.res()
|
||||||
|
} catch (err: any) {
|
||||||
|
next.rej(err.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
doTransaction(exec: TX) {
|
||||||
if (this.pendingTx) {
|
if (this.pendingTx) {
|
||||||
throw new Error("cannot start transaction")
|
throw new Error("cannot start transaction")
|
||||||
}
|
}
|
||||||
|
|
@ -50,15 +77,12 @@ export default class {
|
||||||
try {
|
try {
|
||||||
await exec(tx)
|
await exec(tx)
|
||||||
console.log("tx done")
|
console.log("tx done")
|
||||||
this.pendingTx = false
|
this.ExecNextInQueue()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("tx err")
|
console.log("tx err")
|
||||||
this.pendingTx = false
|
this.ExecNextInQueue()
|
||||||
throw err
|
throw err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue