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

+6 -8
View File
@@ -5321,7 +5321,7 @@ type rpcPaymentIntent struct {
outgoingChannelIDs []uint64
lastHop *route.Vertex
destFeatures *lnwire.FeatureVector
paymentAddr *[32]byte
paymentAddr fn.Option[[32]byte]
payReq []byte
metadata []byte
blindedPathSet *routing.BlindedPaymentPathSet
@@ -5530,8 +5530,9 @@ func (r *rpcServer) extractPaymentIntent(rpcPayReq *rpcPaymentRequest) (rpcPayme
// Note that the payment address for the payIntent should be nil if none
// was provided with the rpcPaymentRequest.
if len(rpcPayReq.PaymentAddr) != 0 {
payIntent.paymentAddr = &[32]byte{}
copy(payIntent.paymentAddr[:], rpcPayReq.PaymentAddr)
var addr [32]byte
copy(addr[:], rpcPayReq.PaymentAddr)
payIntent.paymentAddr = fn.Some(addr)
}
// Otherwise, If the payment request field was not specified
@@ -7380,10 +7381,7 @@ func (r *rpcServer) DecodePayReq(ctx context.Context,
}
// Extract the payment address from the payment request, if present.
var paymentAddr []byte
if payReq.PaymentAddr != nil {
paymentAddr = payReq.PaymentAddr[:]
}
paymentAddr := payReq.PaymentAddr.UnwrapOr([32]byte{})
dest := payReq.Destination.SerializeCompressed()
return &lnrpc.PayReq{
@@ -7399,7 +7397,7 @@ func (r *rpcServer) DecodePayReq(ctx context.Context,
CltvExpiry: int64(payReq.MinFinalCLTVExpiry()),
RouteHints: routeHints,
BlindedPaths: blindedPaymentPaths,
PaymentAddr: paymentAddr,
PaymentAddr: paymentAddr[:],
Features: invoicesrpc.CreateRPCFeatures(payReq.Features),
}, nil
}