fix
This commit is contained in:
parent
29879a027c
commit
20d2afa464
7 changed files with 22 additions and 22 deletions
|
|
@ -91,6 +91,9 @@ export class LiquidityProvider {
|
|||
}
|
||||
|
||||
GetLatestMaxWithdrawable = async (fetch = false) => {
|
||||
if (!this.pubDestination) {
|
||||
return 0
|
||||
}
|
||||
if (this.latestMaxWithdrawable === null) {
|
||||
this.log("liquidity provider is not ready yet")
|
||||
return 0
|
||||
|
|
@ -102,6 +105,9 @@ export class LiquidityProvider {
|
|||
}
|
||||
|
||||
GetLatestBalance = async (fetch = false) => {
|
||||
if (!this.pubDestination) {
|
||||
return 0
|
||||
}
|
||||
if (this.latestMaxWithdrawable === null) {
|
||||
this.log("liquidity provider is not ready yet")
|
||||
return 0
|
||||
|
|
|
|||
|
|
@ -191,7 +191,7 @@ export default class {
|
|||
this.sendOperationToNostr(userInvoice.linkedApplication, userInvoice.user.user_id, op)
|
||||
this.createZapReceipt(log, userInvoice)
|
||||
log("paid invoice processed successfully")
|
||||
await this.liquidityManager.afterInInvoicePaid()
|
||||
this.liquidityManager.afterInInvoicePaid()
|
||||
} catch (err: any) {
|
||||
log(ERROR, "cannot process paid invoice", err.message || "")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,6 +72,13 @@ export class LiquidityManager {
|
|||
return 'provider'
|
||||
}
|
||||
afterInInvoicePaid = async () => {
|
||||
try {
|
||||
await this.orderChannelIfNeeded()
|
||||
} catch (e: any) {
|
||||
this.log("error ordering channel", e)
|
||||
}
|
||||
}
|
||||
orderChannelIfNeeded = async () => {
|
||||
const existingOrder = await this.storage.liquidityStorage.GetLatestLspOrder()
|
||||
if (existingOrder) {
|
||||
return
|
||||
|
|
|
|||
|
|
@ -104,10 +104,10 @@ export default class SanityChecker {
|
|||
}
|
||||
if (entry.paid_at_unix === -1) {
|
||||
this.decrementEvents[invoice] = { userId, refund: amt, failure: true }
|
||||
} else {
|
||||
return
|
||||
}
|
||||
const refund = amt - (entry.paid_amount + entry.routing_fees + entry.service_fees)
|
||||
this.decrementEvents[invoice] = { userId, refund, failure: false }
|
||||
}
|
||||
if (!entry.internal && !entry.liquidityProvider) {
|
||||
const lndEntry = this.payments.find(i => i.paymentRequest === invoice)
|
||||
if (!lndEntry) {
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ export class Watchdog {
|
|||
const walletBalance = await this.lnd.GetWalletBalance()
|
||||
this.log(Number(walletBalance.confirmedBalance), "sats in chain wallet")
|
||||
const channelsBalance = await this.lnd.GetChannelBalance()
|
||||
getLogger({ component: "debugLndBalancev3" })({ w: walletBalance, c: channelsBalance, u: usersTotal, f: this.accumulatedHtlcFees })
|
||||
// getLogger({ component: "debugLndBalancev3" })({ w: walletBalance, c: channelsBalance, u: usersTotal, f: this.accumulatedHtlcFees })
|
||||
const totalLightningBalanceMsats = (channelsBalance.localBalance?.msat || 0n) + (channelsBalance.unsettledLocalBalance?.msat || 0n)
|
||||
const totalLightningBalance = Math.ceil(Number(totalLightningBalanceMsats) / 1000)
|
||||
const feesPaidForLiquidity = this.liquidityManager.GetPaidFees()
|
||||
|
|
|
|||
|
|
@ -99,18 +99,10 @@ export default class Handler {
|
|||
log = getLogger({ component: "nostrMiddleware" })
|
||||
constructor(settings: NostrSettings, eventCallback: (event: NostrEvent) => void) {
|
||||
this.settings = settings
|
||||
this.log(
|
||||
{
|
||||
...settings,
|
||||
apps: settings.apps.map(app => {
|
||||
const { privateKey, ...rest } = app;
|
||||
return {
|
||||
...rest,
|
||||
nprofile: encodeNprofile({ pubkey: rest.publicKey, relays: settings.relays })
|
||||
}
|
||||
this.log("connecting to relays:", settings.relays)
|
||||
this.settings.apps.forEach(app => {
|
||||
this.log("appId:", app.appId, "pubkey:", app.publicKey, "nprofile:", encodeNprofile({ pubkey: app.publicKey, relays: settings.relays }))
|
||||
})
|
||||
}
|
||||
)
|
||||
this.eventCallback = eventCallback
|
||||
this.settings.apps.forEach(app => {
|
||||
this.apps[app.publicKey] = app
|
||||
|
|
|
|||
|
|
@ -20,21 +20,17 @@ export default class {
|
|||
|
||||
PushToQueue<T>(op: TxOperation<T>) {
|
||||
if (!this.pendingTx) {
|
||||
this.log("queue empty, starting transaction", this.transactionsQueue.length)
|
||||
return this.execQueueItem(op)
|
||||
}
|
||||
this.log("queue not empty, possibly stuck")
|
||||
return new Promise<T>((res, rej) => {
|
||||
this.transactionsQueue.push({ op, res, rej })
|
||||
})
|
||||
}
|
||||
|
||||
async execNextInQueue() {
|
||||
this.log("executing next in queue")
|
||||
this.pendingTx = false
|
||||
const next = this.transactionsQueue.pop()
|
||||
if (!next) {
|
||||
this.log("queue is clear")
|
||||
return
|
||||
}
|
||||
try {
|
||||
|
|
@ -51,7 +47,6 @@ export default class {
|
|||
throw new Error("cannot start DB transaction")
|
||||
}
|
||||
this.pendingTx = true
|
||||
this.log("starting", op.dbTx ? "db transaction" : "operation", op.description || "")
|
||||
if (op.dbTx) {
|
||||
return this.doTransaction(op.exec)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue