@@ -266,6 +266,60 @@ func CreateRPCRouteHints(routeHints [][]zpay32.HopHint) []*lnrpc.RouteHint {
266266 return res
267267}
268268
269+ // CreateRPCBlindedPayments takes a set of zpay32.BlindedPaymentPath and
270+ // converts them into a set of lnrpc.BlindedPaymentPaths.
271+ func CreateRPCBlindedPayments (blindedPaths []* zpay32.BlindedPaymentPath ) (
272+ []* lnrpc.BlindedPaymentPath , error ) {
273+
274+ var res []* lnrpc.BlindedPaymentPath
275+ for _ , path := range blindedPaths {
276+ features := path .Features .Features ()
277+ var featuresSlice []lnrpc.FeatureBit
278+ for feature := range features {
279+ featuresSlice = append (
280+ featuresSlice , lnrpc .FeatureBit (feature ),
281+ )
282+ }
283+
284+ if len (path .Hops ) == 0 {
285+ return nil , fmt .Errorf ("each blinded path must " +
286+ "contain at least one hop" )
287+ }
288+
289+ var hops []* lnrpc.BlindedHop
290+ for _ , hop := range path .Hops {
291+ blindedNodeID := hop .BlindedNodePub .
292+ SerializeCompressed ()
293+ hops = append (hops , & lnrpc.BlindedHop {
294+ BlindedNode : blindedNodeID ,
295+ EncryptedData : hop .CipherText ,
296+ })
297+ }
298+
299+ introNode := path .Hops [0 ].BlindedNodePub
300+ firstBlindingPoint := path .FirstEphemeralBlindingPoint
301+
302+ blindedPath := & lnrpc.BlindedPath {
303+ IntroductionNode : introNode .SerializeCompressed (),
304+ BlindingPoint : firstBlindingPoint .
305+ SerializeCompressed (),
306+ BlindedHops : hops ,
307+ }
308+
309+ res = append (res , & lnrpc.BlindedPaymentPath {
310+ BlindedPath : blindedPath ,
311+ BaseFeeMsat : uint64 (path .FeeBaseMsat ),
312+ ProportionalFeeRate : path .FeeRate ,
313+ TotalCltvDelta : uint32 (path .CltvExpiryDelta ),
314+ HtlcMinMsat : path .HTLCMinMsat ,
315+ HtlcMaxMsat : path .HTLCMaxMsat ,
316+ Features : featuresSlice ,
317+ })
318+ }
319+
320+ return res , nil
321+ }
322+
269323// CreateZpay32HopHints takes in the lnrpc form of route hints and converts them
270324// into an invoice decoded form.
271325func CreateZpay32HopHints (routeHints []* lnrpc.RouteHint ) ([][]zpay32.HopHint , error ) {
0 commit comments