@@ -200,6 +200,35 @@ where
200200 invoice = invoice. amount_milli_satoshis ( amt) ;
201201 }
202202
203+ for route_hint in select_phantom_hints ( amt_msat, phantom_route_hints, logger) {
204+ invoice = invoice. private_route ( route_hint) ;
205+ }
206+
207+ let raw_invoice = match invoice. build_raw ( ) {
208+ Ok ( inv) => inv,
209+ Err ( e) => return Err ( SignOrCreationError :: CreationError ( e) )
210+ } ;
211+ let hrp_str = raw_invoice. hrp . to_string ( ) ;
212+ let hrp_bytes = hrp_str. as_bytes ( ) ;
213+ let data_without_signature = raw_invoice. data . to_base32 ( ) ;
214+ let signed_raw_invoice = raw_invoice. sign ( |_| node_signer. sign_invoice ( hrp_bytes, & data_without_signature, Recipient :: PhantomNode ) ) ;
215+ match signed_raw_invoice {
216+ Ok ( inv) => Ok ( Invoice :: from_signed ( inv) . unwrap ( ) ) ,
217+ Err ( e) => Err ( SignOrCreationError :: SignError ( e) )
218+ }
219+ }
220+
221+ /// Utility to select route hints for phantom invoices.
222+ /// See [`PhantomKeysManager`] for more information on phantom node payments.
223+ ///
224+ /// [`PhantomKeysManager`]: lightning::chain::keysinterface::PhantomKeysManager
225+ fn select_phantom_hints < L : Deref > ( amt_msat : Option < u64 > , phantom_route_hints : Vec < PhantomRouteHints > ,
226+ logger : L ) -> Vec < RouteHint >
227+ where
228+ L :: Target : Logger ,
229+ {
230+ let mut phantom_hints : Vec < RouteHint > = Vec :: new ( ) ;
231+
203232 for PhantomRouteHints { channels, phantom_scid, real_node_pubkey } in phantom_route_hints {
204233 log_trace ! ( logger, "Generating phantom route hints for node {}" ,
205234 log_pubkey!( real_node_pubkey) ) ;
@@ -223,22 +252,12 @@ where
223252 cltv_expiry_delta : MIN_CLTV_EXPIRY_DELTA ,
224253 htlc_minimum_msat : None ,
225254 htlc_maximum_msat : None , } ) ;
226- invoice = invoice. private_route ( route_hint. clone ( ) ) ;
255+
256+ phantom_hints. push ( route_hint. clone ( ) ) ;
227257 }
228258 }
229259
230- let raw_invoice = match invoice. build_raw ( ) {
231- Ok ( inv) => inv,
232- Err ( e) => return Err ( SignOrCreationError :: CreationError ( e) )
233- } ;
234- let hrp_str = raw_invoice. hrp . to_string ( ) ;
235- let hrp_bytes = hrp_str. as_bytes ( ) ;
236- let data_without_signature = raw_invoice. data . to_base32 ( ) ;
237- let signed_raw_invoice = raw_invoice. sign ( |_| node_signer. sign_invoice ( hrp_bytes, & data_without_signature, Recipient :: PhantomNode ) ) ;
238- match signed_raw_invoice {
239- Ok ( inv) => Ok ( Invoice :: from_signed ( inv) . unwrap ( ) ) ,
240- Err ( e) => Err ( SignOrCreationError :: SignError ( e) )
241- }
260+ phantom_hints
242261}
243262
244263#[ cfg( feature = "std" ) ]
0 commit comments