@@ -425,6 +425,40 @@ static struct route **convert_flows_to_routes(const tal_t *ctx,
425425 return routes ;
426426}
427427
428+ static void json_add_getroutes (struct json_stream * js ,
429+ struct route * * routes ,
430+ const struct amount_msat * amounts ,
431+ double probability ,
432+ u32 final_cltv )
433+ {
434+ json_add_u64 (js , "probability_ppm" , (u64 )(probability * 1000000 ));
435+ json_array_start (js , "routes" );
436+ for (size_t i = 0 ; i < tal_count (routes ); i ++ ) {
437+ json_object_start (js , NULL );
438+ json_add_u64 (js , "probability_ppm" ,
439+ (u64 )(routes [i ]-> success_prob * 1000000 ));
440+ json_add_amount_msat (js , "amount_msat" , amounts [i ]);
441+ json_add_u32 (js , "final_cltv" , final_cltv );
442+ json_array_start (js , "path" );
443+ for (size_t j = 0 ; j < tal_count (routes [i ]-> hops ); j ++ ) {
444+ struct short_channel_id_dir scidd ;
445+ const struct route_hop * r = & routes [i ]-> hops [j ];
446+ json_object_start (js , NULL );
447+ scidd .scid = r -> scid ;
448+ scidd .dir = r -> direction ;
449+ json_add_short_channel_id_dir (
450+ js , "short_channel_id_dir" , scidd );
451+ json_add_node_id (js , "next_node_id" , & r -> node_id );
452+ json_add_amount_msat (js , "amount_msat" , r -> amount );
453+ json_add_u32 (js , "delay" , r -> delay );
454+ json_object_end (js );
455+ }
456+ json_array_end (js );
457+ json_object_end (js );
458+ }
459+ json_array_end (js );
460+ }
461+
428462/* Returns an error message, or sets *routes */
429463static const char * get_routes (const tal_t * ctx ,
430464 struct command * cmd ,
@@ -585,30 +619,8 @@ static struct command_result *do_getroutes(struct command *cmd,
585619 return command_fail (cmd , PAY_ROUTE_NOT_FOUND , "%s" , err );
586620
587621 response = jsonrpc_stream_success (cmd );
588- json_add_u64 (response , "probability_ppm" , (u64 )(probability * 1000000 ));
589- json_array_start (response , "routes" );
590- for (size_t i = 0 ; i < tal_count (routes ); i ++ ) {
591- json_object_start (response , NULL );
592- json_add_u64 (response , "probability_ppm" , (u64 )(routes [i ]-> success_prob * 1000000 ));
593- json_add_amount_msat (response , "amount_msat" , amounts [i ]);
594- json_add_u32 (response , "final_cltv" , * info -> finalcltv );
595- json_array_start (response , "path" );
596- for (size_t j = 0 ; j < tal_count (routes [i ]-> hops ); j ++ ) {
597- struct short_channel_id_dir scidd ;
598- const struct route_hop * r = & routes [i ]-> hops [j ];
599- json_object_start (response , NULL );
600- scidd .scid = r -> scid ;
601- scidd .dir = r -> direction ;
602- json_add_short_channel_id_dir (response , "short_channel_id_dir" , scidd );
603- json_add_node_id (response , "next_node_id" , & r -> node_id );
604- json_add_amount_msat (response , "amount_msat" , r -> amount );
605- json_add_u32 (response , "delay" , r -> delay );
606- json_object_end (response );
607- }
608- json_array_end (response );
609- json_object_end (response );
610- }
611- json_array_end (response );
622+ json_add_getroutes (response , routes , amounts , probability ,
623+ * info -> finalcltv );
612624 return command_finished (cmd , response );
613625}
614626
0 commit comments