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

Commit 65f334b

Browse files
authored
feat: add ldk custom tlvs to metadata custom records (#445)
1 parent 487848f commit 65f334b

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/davrux/echo-logrus/v4 v4.0.3
1111
github.com/elnosh/gonuts v0.1.1-0.20240602162005-49da741613e4
1212
github.com/getAlby/glalby-go v0.0.0-20240416174357-e6e2faa2fbd8
13-
github.com/getAlby/ldk-node-go v0.0.0-20240613043419-a3ae86f6a26d
13+
github.com/getAlby/ldk-node-go v0.0.0-20240614062656-d4de573a1996
1414
github.com/go-gormigrate/gormigrate/v2 v2.1.1
1515
github.com/gorilla/sessions v1.2.2
1616
github.com/labstack/echo-contrib v0.14.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwV
188188
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
189189
github.com/getAlby/glalby-go v0.0.0-20240416174357-e6e2faa2fbd8 h1:mJsdhUb8hmSSSLR2GQFw9BGtnJP7xmKB/XQxDt3DvAo=
190190
github.com/getAlby/glalby-go v0.0.0-20240416174357-e6e2faa2fbd8/go.mod h1:ViyJvjlvv0GCesTJ7mb3fBo4G+/qsujDAFN90xZ7a9U=
191-
github.com/getAlby/ldk-node-go v0.0.0-20240613043419-a3ae86f6a26d h1:pj+/wYZ3TFzJt2fGQaf7naAqWluR0HlzLGNFAiwoe3g=
192-
github.com/getAlby/ldk-node-go v0.0.0-20240613043419-a3ae86f6a26d/go.mod h1:8BRjtKcz8E0RyYTPEbMS8VIdgredcGSLne8vHDtcRLg=
191+
github.com/getAlby/ldk-node-go v0.0.0-20240614062656-d4de573a1996 h1:UULF8HX3z0kxgppzDX67oG/7t1Es+tpZogqtsYsguX0=
192+
github.com/getAlby/ldk-node-go v0.0.0-20240614062656-d4de573a1996/go.mod h1:8BRjtKcz8E0RyYTPEbMS8VIdgredcGSLne8vHDtcRLg=
193193
github.com/getsentry/raven-go v0.2.0 h1:no+xWJRb5ZI7eE8TWgIq1jLulQiIoLG0IfYxv5JYMGs=
194194
github.com/getsentry/raven-go v0.2.0/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ=
195195
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=

lnclient/ldk/ldk.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import (
1717

1818
"github.com/getAlby/ldk-node-go/ldk_node"
1919
// "github.com/getAlby/nostr-wallet-connect/ldk_node"
20+
b64 "encoding/base64"
21+
2022
decodepay "github.com/nbd-wtf/ln-decodepay"
2123
"github.com/sirupsen/logrus"
2224

@@ -964,6 +966,7 @@ func (ls *LDKService) ldkPaymentToTransaction(payment *ldk_node.PaymentDetails)
964966
var settledAt *int64
965967
preimage := ""
966968
paymentHash := ""
969+
metadata := map[string]interface{}{}
967970

968971
bolt11PaymentKind, isBolt11PaymentKind := payment.Kind.(ldk_node.PaymentKindBolt11)
969972

@@ -998,10 +1001,8 @@ func (ls *LDKService) ldkPaymentToTransaction(payment *ldk_node.PaymentDetails)
9981001
spontaneousPaymentKind, isSpontaneousPaymentKind := payment.Kind.(ldk_node.PaymentKindSpontaneous)
9991002
if isSpontaneousPaymentKind {
10001003
// keysend payment
1001-
// currently no access to created at or the TLVs to get the description
1002-
// TODO: store these in NWC database
10031004
lastUpdate := int64(payment.LastUpdate)
1004-
// TODO: use proper created at time
1005+
// TODO: use proper created at time (currently no access to created time for keysend payments)
10051006
createdAt = lastUpdate
10061007
if payment.Status == ldk_node.PaymentStatusSucceeded {
10071008
settledAt = &lastUpdate
@@ -1010,6 +1011,11 @@ func (ls *LDKService) ldkPaymentToTransaction(payment *ldk_node.PaymentDetails)
10101011
if spontaneousPaymentKind.Preimage != nil {
10111012
preimage = *spontaneousPaymentKind.Preimage
10121013
}
1014+
customRecords := map[string]string{}
1015+
for _, tlv := range spontaneousPaymentKind.CustomTlvs {
1016+
customRecords[strconv.FormatUint(tlv.Type, 10)] = b64.StdEncoding.EncodeToString(tlv.Value)
1017+
}
1018+
metadata["custom_records"] = customRecords
10131019
}
10141020

10151021
var amount uint64 = 0
@@ -1034,6 +1040,7 @@ func (ls *LDKService) ldkPaymentToTransaction(payment *ldk_node.PaymentDetails)
10341040
Description: description,
10351041
DescriptionHash: descriptionHash,
10361042
ExpiresAt: expiresAt,
1043+
Metadata: metadata,
10371044
}, nil
10381045
}
10391046

0 commit comments

Comments
 (0)