alby-hub/transactions/hold_invoice_self_payment_consumer.go
Roland b49818de07
fix: intercept self hold payments based on invoice rather than payment hash (#2027)
* fix: intercept self hold payments based on invoice rather than payment hash

* fix: generate test invoices with long expiry

* fix: add timeout seconds for standard lnd payments
2026-02-27 10:22:24 +05:30

31 lines
1.1 KiB
Go

package transactions
import (
"context"
"github.com/getAlby/hub/db"
"github.com/getAlby/hub/events"
)
type holdInvoiceUpdatedConsumer struct {
paymentRequest string
settledChannel chan<- *db.Transaction
canceledChannel chan<- *db.Transaction
}
func newHoldInvoiceUpdatedConsumer(paymentRequest string, settledChannel chan<- *db.Transaction, canceledChannel chan<- *db.Transaction) *holdInvoiceUpdatedConsumer {
return &holdInvoiceUpdatedConsumer{
paymentRequest: paymentRequest,
settledChannel: settledChannel,
canceledChannel: canceledChannel,
}
}
func (consumer *holdInvoiceUpdatedConsumer) ConsumeEvent(ctx context.Context, event *events.Event, globalProperties map[string]interface{}) {
if event.Event == "nwc_payment_received" && event.Properties.(*db.Transaction).PaymentRequest == consumer.paymentRequest {
consumer.settledChannel <- event.Properties.(*db.Transaction)
}
if event.Event == "nwc_hold_invoice_canceled" && event.Properties.(*db.Transaction).PaymentRequest == consumer.paymentRequest {
consumer.canceledChannel <- event.Properties.(*db.Transaction)
}
}