@@ -58,7 +58,6 @@ pub const MAX_TIMEOUT: u32 = i32::MAX as u32;
5858pub const MIN_RESUME_TIMEOUT : u32 = 500 ;
5959pub const MAX_RESUME_TIMEOUT : u32 = 3000 ;
6060pub const ENDPOINT_CACHE_TIMEOUT : u64 = 10 * 60 * 1000 ;
61-
6261pub const API_VERSION : & str = "v2" ;
6362pub const REST_API_PORT : u16 = 8600 ;
6463pub const ENDPOINT_MESSAGES : & str = "messages" ;
@@ -472,7 +471,7 @@ pub fn construct_rest_api_endpoint(original: &str) -> ClientResult<Url> {
472471 Ok ( url)
473472}
474473
475- fn get_redirection_data ( data : & Value ) -> ( Option < String > , Option < Result < Url , ClientError > > ) {
474+ fn get_redirection_data ( data : & Value ) -> ( Option < String > , Option < Url > ) {
476475 // TODO: Add type RedirectionData
477476 let producers_opt = data. get ( "result" ) . and_then ( |res| res. get ( "producers" ) ) . or_else ( || {
478477 data. get ( "node_error" )
@@ -485,7 +484,8 @@ fn get_redirection_data(data: &Value) -> (Option<String>, Option<Result<Url, Cli
485484 . and_then ( |val| val. as_array ( ) )
486485 . and_then ( |arr| arr. first ( ) )
487486 . and_then ( |v| v. as_str ( ) )
488- . map ( |s| construct_rest_api_endpoint ( s) ) ;
487+ . map ( |s| construct_rest_api_endpoint ( s) . ok ( ) )
488+ . flatten ( ) ;
489489
490490 let thread_id = data
491491 . get ( "node_error" )
@@ -730,7 +730,7 @@ impl ServerLink {
730730 let result = self
731731 . client_env
732732 . fetch (
733- & endpoint. to_string ( ) ,
733+ endpoint. as_str ( ) ,
734734 FetchMethod :: Post ,
735735 Some ( headers. clone ( ) ) ,
736736 Some ( request. clone ( ) ) ,
@@ -965,16 +965,9 @@ impl ServerLink {
965965 while attempts < self . config . message_retries_count {
966966 attempts += 1 ;
967967 if let Ok ( ref data) = result {
968- let ( _, res) = get_redirection_data ( data) ;
969- if let Some ( res) = res {
970- match res {
971- Ok ( bk_url) => {
972- network_state. update_bk_send_message_endpoint ( Some ( bk_url) ) . await ;
973- }
974- Err ( err) => {
975- log:: error!( "{err}" )
976- }
977- }
968+ let ( _, bk_url) = get_redirection_data ( data) ;
969+ if bk_url. is_some ( ) {
970+ network_state. update_bk_send_message_endpoint ( bk_url) . await ;
978971 }
979972 if let Some ( bm_data) = data. get ( "block_manager" ) {
980973 network_state. update_bm_data ( bm_data) . await ;
@@ -1006,22 +999,15 @@ impl ServerLink {
1006999 network_state. update_bk_send_message_endpoint ( None ) . await ;
10071000 }
10081001
1009- let ( real_thread_id, res ) = get_redirection_data ( & err. data ) ;
1002+ let ( real_thread_id, redirect_url ) = get_redirection_data ( & err. data ) ;
10101003
10111004 if let Some ( thread_id) = real_thread_id {
10121005 message. set_thread_id ( Some ( thread_id) ) ;
10131006 }
10141007
1015- if let Some ( res) = res {
1016- match res {
1017- Ok ( bk_url) => {
1018- network_state. update_bk_send_message_endpoint ( Some ( bk_url) ) . await ;
1019- endpoint = network_state. select_send_message_endpoint ( ) . await ;
1020- }
1021- Err ( err) => {
1022- log:: error!( "{err}" )
1023- }
1024- }
1008+ if let Some ( bk_endpoint) = redirect_url {
1009+ network_state. update_bk_send_message_endpoint ( Some ( bk_endpoint) ) . await ;
1010+ endpoint = network_state. select_send_message_endpoint ( ) . await ;
10251011 }
10261012 result =
10271013 self . query_http ( json ! ( [ message] ) . to_string ( ) , & ensure_resource ( & endpoint) ) . await ;
0 commit comments