- if route_hints.is_empty() {
- route_hints.push(RouteHint(vec![]))
- }
- for route_hint in &mut route_hints {
- route_hint.0.push(RouteHintHop {
- src_node_id: real_node_pubkey,
- short_channel_id: phantom_scid,
- fees: RoutingFees {
- base_msat: 0,
- proportional_millionths: 0,
- },
- cltv_expiry_delta: MIN_CLTV_EXPIRY_DELTA,
- htlc_minimum_msat: None,
- htlc_maximum_msat: None,});
- }
+ let empty_route_hints = route_hints.len() == 0;
+ let mut have_pushed_empty = false;
+ let route_hints = route_hints
+ .chain(core::iter::from_fn(move || {
+ if empty_route_hints && !have_pushed_empty {
+ // set flag of having handled the empty route_hints and ensure empty vector
+ // returned only once
+ have_pushed_empty = true;
+ Some(RouteHint(Vec::new()))
+ } else {
+ None
+ }
+ }))
+ .map(move |mut hint| {
+ hint.0.push(RouteHintHop {
+ src_node_id: real_node_pubkey,
+ short_channel_id: phantom_scid,
+ fees: RoutingFees {
+ base_msat: 0,
+ proportional_millionths: 0,
+ },
+ cltv_expiry_delta: MIN_CLTV_EXPIRY_DELTA,
+ htlc_minimum_msat: None,
+ htlc_maximum_msat: None,
+ });
+ hint
+ });