Skip to content

Commit

Permalink
lndclient: add optional custom records to SendPayment
Browse files Browse the repository at this point in the history
  • Loading branch information
bhandras committed Jun 3, 2020
1 parent ce39d76 commit 0e048cb
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lndclient/router_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ type SendPaymentRequest struct {

// KeySend is set to true if the tlv payload will include the preimage.
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.
Expand Down Expand Up @@ -154,6 +158,9 @@ func (r *routerClient) SendPayment(ctx context.Context,
if request.LastHopPubkey != nil {
rpcReq.LastHopPubkey = request.LastHopPubkey[:]
}

rpcReq.DestCustomRecords = request.CustomRecords

if request.KeySend {
if request.PaymentHash != nil {
return nil, nil, fmt.Errorf(
Expand All @@ -165,10 +172,12 @@ func (r *routerClient) SendPayment(ctx context.Context,
return nil, nil, err
}

// Override the payment hash.
rpcReq.DestCustomRecords = map[uint64][]byte{
record.KeySendType: preimage[:],
if rpcReq.DestCustomRecords == nil {
rpcReq.DestCustomRecords = make(map[uint64][]byte)
}

// Override the payment hash.
rpcReq.DestCustomRecords[record.KeySendType] = preimage[:]
hash := preimage.Hash()
request.PaymentHash = &hash
}
Expand Down

0 comments on commit 0e048cb

Please sign in to comment.