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 {
|
||||
string user_identifier = 1;
|
||||
string base_url_override = 2;
|
||||
}
|
||||
|
||||
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 url = baseUrl ? baseUrl : `${this.settings.serviceUrl}/api/guest/lnurl_pay/handle`
|
||||
return {
|
||||
tag: 'payRequest',
|
||||
callback: `${this.settings.serviceUrl}/api/guest/lnurl_pay/handle?k1=${payK1.key}`,
|
||||
callback: `${url}?k1=${payK1.key}`,
|
||||
maxSendable: 10000000,
|
||||
minSendable: 0,
|
||||
metadata: defaultLnurlPayMetadata
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ export type StorageSettings = {
|
|||
export const LoadStorageSettingsFromEnv = (test = false): StorageSettings => {
|
||||
return { dbSettings: LoadDbSettingsFromEnv(test) }
|
||||
}
|
||||
type TX = (entityManager: EntityManager) => Promise<void>
|
||||
|
||||
export default class {
|
||||
DB: DataSource | EntityManager
|
||||
|
|
@ -30,6 +31,7 @@ export default class {
|
|||
userStorage: UserStorage
|
||||
paymentStorage: PaymentStorage
|
||||
pendingTx: boolean
|
||||
transactionsQueue: { exec: TX, res: () => void, rej: (message: string) => void }[] = []
|
||||
constructor(settings: StorageSettings) {
|
||||
this.settings = settings
|
||||
}
|
||||
|
|
@ -40,7 +42,32 @@ export default class {
|
|||
this.applicationStorage = new ApplicationStorage(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) {
|
||||
throw new Error("cannot start transaction")
|
||||
}
|
||||
|
|
@ -50,15 +77,12 @@ export default class {
|
|||
try {
|
||||
await exec(tx)
|
||||
console.log("tx done")
|
||||
this.pendingTx = false
|
||||
this.ExecNextInQueue()
|
||||
} catch (err) {
|
||||
console.log("tx err")
|
||||
this.pendingTx = false
|
||||
this.ExecNextInQueue()
|
||||
throw err
|
||||
}
|
||||
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue