Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

feat: add LDK payment createdAt and duration to payment sent event #484

Merged
merged 2 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions events/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type PaymentReceivedEventProperties struct {

type PaymentSentEventProperties struct {
PaymentHash string `json:"payment_hash"`
Duration uint64 `json:"duration"`
}

type ChannelBackupEvent struct {
Expand Down
19 changes: 17 additions & 2 deletions lnclient/ldk/ldk.go
Original file line number Diff line number Diff line change
Expand Up @@ -1044,8 +1044,12 @@ func (ls *LDKService) ldkPaymentToTransaction(payment *ldk_node.PaymentDetails)
if isSpontaneousPaymentKind {
// keysend payment
lastUpdate := int64(payment.LastUpdate)
// TODO: use proper created at time (currently no access to created time for keysend payments)
createdAt = lastUpdate
createdAt = int64(payment.CreatedAt)
// TODO: remove this check some point in the future
// all payments after v0.6.2 will have createdAt set
if createdAt == 0 {
createdAt = lastUpdate
}
if payment.Status == ldk_node.PaymentStatusSucceeded {
settledAt = &lastUpdate
}
Expand Down Expand Up @@ -1229,10 +1233,21 @@ func (ls *LDKService) handleLdkEvent(event *ldk_node.Event) {
},
})
case ldk_node.EventPaymentSuccessful:
var duration uint64 = 0
if eventType.PaymentId != nil {
payment := ls.node.Payment(*eventType.PaymentId)
if payment == nil {
logger.Logger.WithField("payment_id", *eventType.PaymentId).Error("could not find LDK payment")
return
}
duration = payment.LastUpdate - payment.CreatedAt
}

ls.eventPublisher.Publish(&events.Event{
Event: "nwc_payment_sent",
Properties: &events.PaymentSentEventProperties{
PaymentHash: eventType.PaymentHash,
Duration: duration,
},
})
}
Expand Down
2 changes: 1 addition & 1 deletion lnclient/ldk/ldk_event_broadcaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"time"

"github.com/getAlby/ldk-node-go/ldk_node"
// "github.com/getAlby/nostr-wallet-connect/ldk_node"
"github.com/getAlby/nostr-wallet-connect/logger"

// "github.com/getAlby/nostr-wallet-connect/ldk_node"
"github.com/sirupsen/logrus"
)

Expand Down
Loading