diff --git a/invoices_client.go b/invoices_client.go index a154384..57d0ad1 100644 --- a/invoices_client.go +++ b/invoices_client.go @@ -3,6 +3,7 @@ package lndclient import ( "context" "errors" + "fmt" "io" "sync" "time" @@ -13,6 +14,7 @@ import ( "github.com/lightningnetwork/lnd/lnrpc/invoicesrpc" "github.com/lightningnetwork/lnd/lntypes" "github.com/lightningnetwork/lnd/lnwire" + "github.com/lightningnetwork/lnd/routing/route" "google.golang.org/grpc" ) @@ -228,13 +230,45 @@ func (s *invoicesClient) AddHoldInvoice(ctx context.Context, rpcCtx, cancel := context.WithTimeout(ctx, s.timeout) defer cancel() + routeHints := make([]*lnrpc.RouteHint, len(in.RouteHints)) + + for ir, rh := range in.RouteHints { + routeHint := &lnrpc.RouteHint{} + routeHint.HopHints = make([]*lnrpc.HopHint, len(rh)) + + for ih, hh := range rh { + hopHint := &lnrpc.HopHint{ + ChanId: hh.ChannelID, + CltvExpiryDelta: uint32(hh.CLTVExpiryDelta), + FeeBaseMsat: hh.FeeBaseMSat, + FeeProportionalMillionths: hh.FeeProportionalMillionths, + } + + peer, err := route.NewVertexFromBytes( + hh.NodeID.SerializeCompressed(), + ) + if err != nil { + return "", fmt.Errorf("failed to encode hop "+ + "hint node ID: %v", err) + } + + hopHint.NodeId = peer.String() + routeHint.HopHints[ih] = hopHint + } + + routeHints[ir] = routeHint + } + rpcIn := &invoicesrpc.AddHoldInvoiceRequest{ - Memo: in.Memo, - Hash: in.Hash[:], - ValueMsat: int64(in.Value), - Expiry: in.Expiry, - CltvExpiry: in.CltvExpiry, - Private: true, + Memo: in.Memo, + Hash: in.Hash[:], + ValueMsat: int64(in.Value), + Expiry: in.Expiry, + CltvExpiry: in.CltvExpiry, + Private: in.Private, + RouteHints: routeHints, + DescriptionHash: in.DescriptionHash, + FallbackAddr: in.FallbackAddr, } rpcCtx = s.invoiceMac.WithMacaroonAuth(rpcCtx)