multi: update PaymentAddr to use fn.Option

Since it is allowed to not be set and so can lead to nil deref panics if
it is a pointer.
This commit is contained in:
Elle Mouton committed 2024-09-25 11:14:35 +09:00
1 parent 84c91f701c
commit 7dc86acb8c
14 files changed
+87 -70

No files matched your search

+9 -2
View File
@@ -14,6 +14,7 @@ import (
"github.com/btcsuite/btcd/btcutil/bech32"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/lightningnetwork/lnd/fn"
"github.com/lightningnetwork/lnd/lnwire"
)
@@ -278,13 +279,19 @@ func parseTaggedFields(invoice *Invoice, fields []byte, net *chaincfg.Params) er
invoice.PaymentHash, err = parse32Bytes(base32Data)
case fieldTypeS:
if invoice.PaymentAddr != nil {
if invoice.PaymentAddr.IsSome() {
// We skip the field if we have already seen a
// supported one.
continue
}
invoice.PaymentAddr, err = parse32Bytes(base32Data)
addr, err := parse32Bytes(base32Data)
if err != nil {
return err
}
if addr != nil {
invoice.PaymentAddr = fn.Some(*addr)
}
case fieldTypeD:
if invoice.Description != nil {