clink req clogging
This commit is contained in:
parent
516443ed9e
commit
1cbeb951bb
3 changed files with 49 additions and 3 deletions
|
|
@ -49,6 +49,12 @@ export default (serverMethods: Types.ServerMethods, mainHandler: Main, nostrSett
|
||||||
}
|
}
|
||||||
if (event.kind === 21001) {
|
if (event.kind === 21001) {
|
||||||
const offerReq = j as NofferData
|
const offerReq = j as NofferData
|
||||||
|
log("🎯 [NOSTR EVENT] Received offer request (kind 21001)", {
|
||||||
|
fromPub: event.pub,
|
||||||
|
appId: event.appId,
|
||||||
|
eventId: event.id,
|
||||||
|
offer: offerReq.offer
|
||||||
|
})
|
||||||
mainHandler.offerManager.handleNip69Noffer(offerReq, event)
|
mainHandler.offerManager.handleNip69Noffer(offerReq, event)
|
||||||
return
|
return
|
||||||
} else if (event.kind === 21002) {
|
} else if (event.kind === 21002) {
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ export class OfferManager {
|
||||||
storage: Storage
|
storage: Storage
|
||||||
lnd: LND
|
lnd: LND
|
||||||
liquidityManager: LiquidityManager
|
liquidityManager: LiquidityManager
|
||||||
logger = getLogger({ component: 'DebitManager' })
|
logger = getLogger({ component: 'OfferManager' })
|
||||||
constructor(storage: Storage, settings: MainSettings, lnd: LND, applicationManager: ApplicationManager, productManager: ProductManager, liquidityManager: LiquidityManager) {
|
constructor(storage: Storage, settings: MainSettings, lnd: LND, applicationManager: ApplicationManager, productManager: ProductManager, liquidityManager: LiquidityManager) {
|
||||||
this.storage = storage
|
this.storage = storage
|
||||||
this.settings = settings
|
this.settings = settings
|
||||||
|
|
@ -152,15 +152,46 @@ export class OfferManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleNip69Noffer(offerReq: NofferData, event: NostrEvent) {
|
async handleNip69Noffer(offerReq: NofferData, event: NostrEvent) {
|
||||||
|
this.logger("📥 [OFFER REQUEST] Received offer request", {
|
||||||
|
fromPub: event.pub,
|
||||||
|
appId: event.appId,
|
||||||
|
eventId: event.id,
|
||||||
|
offer: offerReq.offer,
|
||||||
|
amount: offerReq.amount_sats,
|
||||||
|
payerData: offerReq.payer_data
|
||||||
|
})
|
||||||
|
|
||||||
const offerInvoice = await this.getNofferInvoice(offerReq, event.appId)
|
const offerInvoice = await this.getNofferInvoice(offerReq, event.appId)
|
||||||
|
|
||||||
if (!offerInvoice.success) {
|
if (!offerInvoice.success) {
|
||||||
const code = offerInvoice.code
|
const code = offerInvoice.code
|
||||||
|
this.logger("❌ [OFFER REJECTED] Offer request failed", {
|
||||||
|
fromPub: event.pub,
|
||||||
|
eventId: event.id,
|
||||||
|
code,
|
||||||
|
error: codeToMessage(code),
|
||||||
|
max: offerInvoice.max
|
||||||
|
})
|
||||||
const e = newNofferResponse(JSON.stringify({ code, error: codeToMessage(code), range: { min: 10, max: offerInvoice.max } }), event)
|
const e = newNofferResponse(JSON.stringify({ code, error: codeToMessage(code), range: { min: 10, max: offerInvoice.max } }), event)
|
||||||
this.nostrSend({ type: 'app', appId: event.appId }, { type: 'event', event: e, encrypt: { toPub: event.pub } })
|
this.nostrSend({ type: 'app', appId: event.appId }, { type: 'event', event: e, encrypt: { toPub: event.pub } })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logger("✅ [OFFER SUCCESS] Generated invoice for offer request", {
|
||||||
|
fromPub: event.pub,
|
||||||
|
eventId: event.id,
|
||||||
|
invoice: offerInvoice.invoice.substring(0, 50) + "...",
|
||||||
|
offer: offerReq.offer
|
||||||
|
})
|
||||||
|
|
||||||
const e = newNofferResponse(JSON.stringify({ bolt11: offerInvoice.invoice }), event)
|
const e = newNofferResponse(JSON.stringify({ bolt11: offerInvoice.invoice }), event)
|
||||||
this.nostrSend({ type: 'app', appId: event.appId }, { type: 'event', event: e, encrypt: { toPub: event.pub } })
|
this.nostrSend({ type: 'app', appId: event.appId }, { type: 'event', event: e, encrypt: { toPub: event.pub } })
|
||||||
|
|
||||||
|
this.logger("📤 [OFFER RESPONSE] Sent offer response", {
|
||||||
|
toPub: event.pub,
|
||||||
|
eventId: event.id,
|
||||||
|
responseEventId: "generated"
|
||||||
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -200,7 +231,7 @@ export class OfferManager {
|
||||||
}
|
}
|
||||||
const { passed, validated } = this.ValidateExpectedData(userOffer, offerReq.payer_data)
|
const { passed, validated } = this.ValidateExpectedData(userOffer, offerReq.payer_data)
|
||||||
if (!passed) {
|
if (!passed) {
|
||||||
console.log("Invalid expected data", validated)
|
this.logger("Invalid expected data", validated || {})
|
||||||
return { success: false, code: 1, max: remote }
|
return { success: false, code: 1, max: remote }
|
||||||
}
|
}
|
||||||
const res = await this.applicationManager.AddAppUserInvoice(appId, {
|
const res = await this.applicationManager.AddAppUserInvoice(appId, {
|
||||||
|
|
|
||||||
|
|
@ -188,11 +188,20 @@ export default class Handler {
|
||||||
relay.close()
|
relay.close()
|
||||||
this.Connect()
|
this.Connect()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const appIds = Object.keys(this.apps)
|
||||||
|
log("🔍 [NOSTR SUBSCRIPTION] Setting up subscription", {
|
||||||
|
since: Math.ceil(Date.now() / 1000),
|
||||||
|
kinds: supportedKinds,
|
||||||
|
appIds: appIds,
|
||||||
|
listeningForPubkeys: appIds
|
||||||
|
})
|
||||||
|
|
||||||
const sub = relay.subscribe([
|
const sub = relay.subscribe([
|
||||||
{
|
{
|
||||||
since: Math.ceil(Date.now() / 1000),
|
since: Math.ceil(Date.now() / 1000),
|
||||||
kinds: supportedKinds,
|
kinds: supportedKinds,
|
||||||
'#p': Object.keys(this.apps),
|
'#p': appIds,
|
||||||
}
|
}
|
||||||
], {
|
], {
|
||||||
oneose: () => {
|
oneose: () => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue