Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show tlv records in transaction popup #365

Merged
merged 23 commits into from
Aug 9, 2024
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
33a5714
feat: show tlv records in transaction popup
im-adithya Jul 29, 2024
832bbf4
chore: add podcastinginfo component
im-adithya Jul 30, 2024
10afe14
chore: remove ? in podcasting info component
im-adithya Jul 30, 2024
65e6752
Merge branch 'master' into task-tlv-records
im-adithya Aug 5, 2024
308e4ff
chore: decode tlv record values in backend
im-adithya Aug 6, 2024
185895f
chore: add backup for tx description
im-adithya Aug 6, 2024
eb84d63
feat: add boostagram column and use jsonb in metadata
im-adithya Aug 6, 2024
a6406a8
chore: do not modify metadata while parsing
im-adithya Aug 7, 2024
25064af
chore: combine boostagram and metadata migration
im-adithya Aug 7, 2024
d9d99c0
feat: extract description from custom records
im-adithya Aug 8, 2024
178410f
chore: fix keysend tests
im-adithya Aug 8, 2024
4ee56dc
chore: change metadata param type in makeinvoice
im-adithya Aug 8, 2024
41c290b
chore: fix make invoice tests
im-adithya Aug 8, 2024
e12433e
chore: metadata fixes
im-adithya Aug 8, 2024
168d7cf
Merge remote-tracking branch 'origin/master' into task-tlv-records
rolznz Aug 8, 2024
3b96728
fix: boostragram and metadata migration
rolznz Aug 8, 2024
7c29b25
chore: set metadata json column to null if empty
im-adithya Aug 8, 2024
8760830
fix: remove jsonb from migration
im-adithya Aug 8, 2024
fe59323
chore: code cleanup, rename api models, fix metadata usage
rolznz Aug 9, 2024
662c01d
fix: metadata format
rolznz Aug 9, 2024
fb30ae6
chore: remove unused contant
rolznz Aug 9, 2024
e6d9930
fix: tests
rolznz Aug 9, 2024
268b69a
chore: improve tests
rolznz Aug 9, 2024
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
89 changes: 7 additions & 82 deletions transactions/transactions_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func (svc *transactionsService) SendKeysend(ctx context.Context, amount uint64,
metadata["destination"] = destination

metadata["tlv_records"] = customRecords
metadataBytes, err := svc.parseMetadata(metadata)
metadataBytes, err := json.Marshal(metadata)
if err != nil {
logger.Logger.WithError(err).Error("Failed to serialize transaction metadata")
return nil, err
Expand Down Expand Up @@ -559,13 +559,13 @@ func (svc *transactionsService) ConsumeEvent(ctx context.Context, event *events.
})

if result.RowsAffected == 0 {
// Note: brand new payments cannot be associated with an app
// TODO: support customkey/customvalue for boostagrams received to isolated apps
description := lnClientTransaction.Description
var metadataBytes []byte
var boostagramBytes []byte
if lnClientTransaction.Metadata != nil {
var err error
metadataBytes, err = svc.parseMetadata(lnClientTransaction.Metadata)
metadataBytes, err = json.Marshal(lnClientTransaction.Metadata)
if err != nil {
logger.Logger.WithError(err).Error("Failed to serialize transaction metadata")
return err
Expand All @@ -574,7 +574,6 @@ func (svc *transactionsService) ConsumeEvent(ctx context.Context, event *events.
var customRecords []lnclient.TLVRecord
customRecords, _ = lnClientTransaction.Metadata["tlv_records"].([]lnclient.TLVRecord)
boostagramBytes = svc.getBoostagramFromCustomRecords(customRecords)

extractedDescription := svc.getDescriptionFromCustomRecords(customRecords)
if extractedDescription != "" {
description = extractedDescription
Expand Down Expand Up @@ -645,50 +644,10 @@ func (svc *transactionsService) ConsumeEvent(ctx context.Context, event *events.
})

if result.RowsAffected == 0 {
// Note: brand new payments cannot be associated with an app
description := lnClientTransaction.Description
var metadataBytes []byte
var boostagramBytes []byte
if lnClientTransaction.Metadata != nil {
var err error
metadataBytes, err = svc.parseMetadata(lnClientTransaction.Metadata)
if err != nil {
logger.Logger.WithError(err).Error("Failed to serialize transaction metadata")
return err
}

var customRecords []lnclient.TLVRecord
customRecords, _ = lnClientTransaction.Metadata["tlv_records"].([]lnclient.TLVRecord)
boostagramBytes = svc.getBoostagramFromCustomRecords(customRecords)

extractedDescription := svc.getDescriptionFromCustomRecords(customRecords)
if extractedDescription != "" {
description = extractedDescription
}
}
var expiresAt *time.Time
if lnClientTransaction.ExpiresAt != nil {
expiresAtValue := time.Unix(*lnClientTransaction.ExpiresAt, 0)
expiresAt = &expiresAtValue
}
dbTransaction = db.Transaction{
Type: constants.TRANSACTION_TYPE_OUTGOING,
AmountMsat: uint64(lnClientTransaction.Amount),
PaymentRequest: lnClientTransaction.Invoice,
PaymentHash: lnClientTransaction.PaymentHash,
Description: description,
DescriptionHash: lnClientTransaction.DescriptionHash,
ExpiresAt: expiresAt,
Metadata: datatypes.JSON(metadataBytes),
Boostagram: datatypes.JSON(boostagramBytes),
}
err := tx.Create(&dbTransaction).Error
if err != nil {
logger.Logger.WithFields(logrus.Fields{
"payment_hash": lnClientTransaction.PaymentHash,
}).WithError(err).Error("Failed to create transaction")
return err
}
// Note: payments made from outside cannot be associated with an app
// for now this is disabled as it only applies to LND, and we do not import LND transactions either.
logger.Logger.WithField("payment_hash", lnClientTransaction.PaymentHash).Error("payment not found")
return NewNotFoundError()
}

settledAt := time.Now()
Expand Down Expand Up @@ -836,40 +795,6 @@ func makePreimageHex() ([]byte, error) {
return bytes, nil
}

func (svc *transactionsService) parseMetadata(metadata lnclient.Metadata) ([]byte, error) {
rolznz marked this conversation as resolved.
Show resolved Hide resolved
var tlvRecords []lnclient.TLVRecord
tlvRecords, _ = metadata["tlv_records"].([]lnclient.TLVRecord)
decodedTlvRecords := append([]lnclient.TLVRecord(nil), tlvRecords...)

for i, record := range tlvRecords {
// TODO: skip other un-encoded tlv values
if record.Type == PreimageTlvType {
continue
}

bytes, err := hex.DecodeString(record.Value)
if err != nil {
logger.Logger.WithError(err).WithFields(logrus.Fields{
"type": record.Type,
"value": record.Value,
}).Error("Failed to decode hex value in tlv record")
continue
}
decodedTlvRecords[i].Value = string(bytes)
}

metadata["tlv_records"] = decodedTlvRecords
metadataBytes, err := json.Marshal(metadata)
if err != nil {
return nil, err
}

// we don't want to modify metadata
metadata["tlv_records"] = tlvRecords

return metadataBytes, nil
}

func (svc *transactionsService) getBoostagramFromCustomRecords(customRecords []lnclient.TLVRecord) []byte {
for _, record := range customRecords {
if record.Type == BoostagramTlvType {
Expand Down
Loading