11use crate :: api:: error:: LdkServerError ;
2+ use crate :: api:: error:: LdkServerErrorCode :: InvalidRequestError ;
23use crate :: service:: Context ;
34use ldk_node:: lightning:: routing:: router:: RouteParametersConfig ;
45use ldk_node:: lightning_invoice:: Bolt11Invoice ;
@@ -13,12 +14,33 @@ pub(crate) fn handle_bolt11_send_request(
1314 let invoice = Bolt11Invoice :: from_str ( & request. invoice . as_str ( ) )
1415 . map_err ( |_| ldk_node:: NodeError :: InvalidInvoice ) ?;
1516
16- let route_parameters = request. route_parameters . map ( |params| RouteParametersConfig {
17- max_total_routing_fee_msat : params. max_total_routing_fee_msat ,
18- max_total_cltv_expiry_delta : params. max_total_cltv_expiry_delta ,
19- max_path_count : params. max_path_count as u8 ,
20- max_channel_saturation_power_of_half : params. max_channel_saturation_power_of_half as u8 ,
21- } ) ;
17+ let route_parameters = match request. route_parameters {
18+ Some ( params) => {
19+ let max_path_count: u8 = params. max_path_count . try_into ( ) . map_err ( |_| {
20+ LdkServerError :: new (
21+ InvalidRequestError ,
22+ format ! ( "Invalid max_path_count, must be between 0 and {}" , u8 :: MAX ) ,
23+ )
24+ } ) ?;
25+ let max_channel_saturation_power_of_half: u8 =
26+ params. max_channel_saturation_power_of_half . try_into ( ) . map_err ( |_| {
27+ LdkServerError :: new (
28+ InvalidRequestError ,
29+ format ! (
30+ "Invalid max_channel_saturation_power_of_half, must be between 0 and {}" ,
31+ u8 :: MAX
32+ ) ,
33+ )
34+ } ) ?;
35+ Some ( RouteParametersConfig {
36+ max_total_routing_fee_msat : params. max_total_routing_fee_msat ,
37+ max_total_cltv_expiry_delta : params. max_total_cltv_expiry_delta ,
38+ max_path_count,
39+ max_channel_saturation_power_of_half,
40+ } )
41+ } ,
42+ None => None ,
43+ } ;
2244
2345 let payment_id = match request. amount_msat {
2446 None => context. node . bolt11_payment ( ) . send ( & invoice, route_parameters) ,
0 commit comments