lndclient: add optional custom records to SendPayment

pull/216/head
Andras Banki-Horvath 4 years ago
parent ce39d76c61
commit 0e048cbe54

@ -117,6 +117,10 @@ type SendPaymentRequest struct {
// KeySend is set to true if the tlv payload will include the preimage. // KeySend is set to true if the tlv payload will include the preimage.
KeySend bool KeySend bool
// CustomRecords holds the custom TLV records that will be added to the
// payment.
CustomRecords map[uint64][]byte
} }
// routerClient is a wrapper around the generated routerrpc proxy. // routerClient is a wrapper around the generated routerrpc proxy.
@ -154,6 +158,9 @@ func (r *routerClient) SendPayment(ctx context.Context,
if request.LastHopPubkey != nil { if request.LastHopPubkey != nil {
rpcReq.LastHopPubkey = request.LastHopPubkey[:] rpcReq.LastHopPubkey = request.LastHopPubkey[:]
} }
rpcReq.DestCustomRecords = request.CustomRecords
if request.KeySend { if request.KeySend {
if request.PaymentHash != nil { if request.PaymentHash != nil {
return nil, nil, fmt.Errorf( return nil, nil, fmt.Errorf(
@ -165,10 +172,12 @@ func (r *routerClient) SendPayment(ctx context.Context,
return nil, nil, err return nil, nil, err
} }
// Override the payment hash. if rpcReq.DestCustomRecords == nil {
rpcReq.DestCustomRecords = map[uint64][]byte{ rpcReq.DestCustomRecords = make(map[uint64][]byte)
record.KeySendType: preimage[:],
} }
// Override the payment hash.
rpcReq.DestCustomRecords[record.KeySendType] = preimage[:]
hash := preimage.Hash() hash := preimage.Hash()
request.PaymentHash = &hash request.PaymentHash = &hash
} }

Loading…
Cancel
Save