Skip to content

Commit

Permalink
fix: keysend custom value decoding (#452)
Browse files Browse the repository at this point in the history
* fix: keysend custom value decoding

* fix: test
  • Loading branch information
rolznz authored Aug 12, 2024
1 parent acd95ff commit 9883292
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion transactions/receive_keysend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package transactions

import (
"context"
"encoding/hex"
"strconv"
"testing"

Expand Down Expand Up @@ -30,7 +31,7 @@ func TestReceiveKeysendWithCustomKey(t *testing.T) {
tlv := []lnclient.TLVRecord{
{
Type: 696969,
Value: strconv.FormatUint(uint64(app.ID), 16),
Value: hex.EncodeToString([]byte(strconv.FormatUint(uint64(app.ID), 10))),
},
}
tx := lnclient.Transaction{
Expand All @@ -55,6 +56,7 @@ func TestReceiveKeysendWithCustomKey(t *testing.T) {
transaction, err := transactionsService.LookupTransaction(ctx, tx.PaymentHash, nil, svc.LNClient, nil)
assert.NoError(t, err)
assert.Equal(t, app.ID, *transaction.AppId)
assert.Equal(t, uint(1), app.ID)
}

func TestReceiveKeysend(t *testing.T) {
Expand Down
9 changes: 7 additions & 2 deletions transactions/transactions_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -855,9 +855,14 @@ func (svc *transactionsService) getAppIdFromCustomRecords(customRecords []lnclie
app := db.App{}
for _, record := range customRecords {
if record.Type == CustomKeyTlvType {
customValue, err := strconv.ParseUint(record.Value, 16, 64)
decodedString, err := hex.DecodeString(record.Value)
if err != nil {
logger.Logger.WithError(err).Error("Failed to parse custom key TLV record")
logger.Logger.WithError(err).Error("Failed to parse custom key TLV record as hex")
continue
}
customValue, err := strconv.ParseUint(string(decodedString), 10, 64)
if err != nil {
logger.Logger.WithError(err).Error("Failed to parse custom key TLV record as number")
continue
}
err = svc.db.Take(&app, &db.App{
Expand Down

0 comments on commit 9883292

Please sign in to comment.