diff --git a/alby.go b/alby.go index 65205486b..7b2e395f0 100644 --- a/alby.go +++ b/alby.go @@ -721,6 +721,16 @@ func albyInvoiceToTransaction(invoice *AlbyInvoice) *Nip47Transaction { settledAt = &settledAtUnix } + var customRecords = map[string]string{} + for key, value := range invoice.CustomRecords { + customRecords[key] = value // already base64 encoded + } + + var metadata = map[string]map[string]string{} + if len(customRecords) != 0 { + metadata["custom_records"] = customRecords + } + return &Nip47Transaction{ Type: invoice.Type, Invoice: invoice.PaymentRequest, @@ -733,6 +743,6 @@ func albyInvoiceToTransaction(invoice *AlbyInvoice) *Nip47Transaction { CreatedAt: invoice.CreatedAt.Unix(), ExpiresAt: expiresAt, SettledAt: settledAt, - Metadata: invoice.Metadata, + Metadata: metadata, } } diff --git a/lnd.go b/lnd.go index 06ab998d0..1c3c5f6f8 100644 --- a/lnd.go +++ b/lnd.go @@ -4,9 +4,11 @@ import ( "context" "crypto/rand" "crypto/sha256" + "encoding/base64" "encoding/hex" "errors" "sort" + "strconv" "strings" "time" @@ -121,6 +123,21 @@ func (svc *LNDService) ListTransactions(ctx context.Context, senderPubkey string settledAt = &settledAtUnix } + var customRecords = map[string]string{} + for _, htlc := range payment.Htlcs { + for _, hop := range htlc.Route.Hops { + for id, value := range hop.CustomRecords { + key := strconv.FormatUint(id, 10) + customRecords[key] = base64.StdEncoding.EncodeToString(value) + } + } + } + + var metadata = map[string]map[string]string{} + if len(customRecords) != 0 { + metadata["custom_records"] = customRecords + } + transaction := Nip47Transaction{ Type: "outgoing", Invoice: payment.PaymentRequest, @@ -133,7 +150,7 @@ func (svc *LNDService) ListTransactions(ctx context.Context, senderPubkey string DescriptionHash: descriptionHash, ExpiresAt: expiresAt, SettledAt: settledAt, - //TODO: Metadata: (e.g. keysend), + Metadata: metadata, } transactions = append(transactions, transaction) } @@ -369,7 +386,17 @@ func lndInvoiceToTransaction(invoice *lnrpc.Invoice) *Nip47Transaction { expiresAtUnix := invoice.CreationDate + invoice.Expiry expiresAt = &expiresAtUnix } - + var customRecords = map[string]string{} + for _, htlc := range invoice.Htlcs { + for id, value := range htlc.CustomRecords { + key := strconv.FormatUint(id, 10) + customRecords[key] = base64.StdEncoding.EncodeToString(value) + } + } + var metadata = map[string]map[string]string{} + if len(customRecords) != 0 { + metadata["custom_records"] = customRecords + } return &Nip47Transaction{ Type: "incoming", Invoice: invoice.PaymentRequest, @@ -382,6 +409,6 @@ func lndInvoiceToTransaction(invoice *lnrpc.Invoice) *Nip47Transaction { CreatedAt: invoice.CreationDate, SettledAt: settledAt, ExpiresAt: expiresAt, - // TODO: Metadata (e.g. keysend) + Metadata: metadata, } } diff --git a/models.go b/models.go index 527cfb46d..784d24d20 100644 --- a/models.go +++ b/models.go @@ -149,7 +149,7 @@ type AlbyInvoice struct { CreatedAt time.Time `json:"created_at"` // CreationDate uint64 `json:"creation_date"` Currency string `json:"currency"` - // custom_records + CustomRecords map[string]string `json:"custom_records,omitempty"` DescriptionHash string `json:"description_hash"` ExpiresAt *time.Time `json:"expires_at"` Expiry uint32 `json:"expiry"`