pub async fn post_message_json(&self, message: &Message) -> Result<MessageId> {
        let path = "api/v1/messages";
        let local_pow = self.get_local_pow().await;
        let timeout = if local_pow {
            self.get_timeout(Api::PostMessage)
        } else {
            self.get_timeout(Api::PostMessageWithRemotePow)
        };
        let message_dto = MessageDto::from(message);

        // fallback to local PoW if remote PoW fails
        let resp: SuccessBody<SubmitMessageResponse> = match self
            .node_manager
            .post_request_json(path, timeout, serde_json::to_value(message_dto)?, local_pow)
            .await
        {
            Ok(res) => res,
            Err(e) => {
                if let Error::NodeError(e) = e {
                    // hornet and bee return different error messages
                    if e == *"No available nodes with remote PoW"
                        || e.contains("proof of work is not enabled")
                        || e.contains("`PoW` not enabled")
                    {
                        let mut client_network_info =
                            self.network_info.write().map_err(|_| crate::Error::PoisonError)?;
                        // switch to local PoW
                        client_network_info.local_pow = true;
                        drop(client_network_info);
                        #[cfg(not(feature = "wasm"))]
                        let msg_res = crate::api::finish_pow(self, message.payload().clone()).await;
                        #[cfg(feature = "wasm")]
                        let msg_res = {
                            let min_pow_score = self.get_min_pow_score().await?;
                            let network_id = self.get_network_id().await?;
                            crate::api::finish_single_thread_pow(
                                self,
                                network_id,
                                None,
                                message.payload().clone(),
                                min_pow_score,
                            )
                            .await
                        };
                        let message_with_local_pow = match msg_res {
                            Ok(msg) => {
                                // reset local PoW state
                                let mut client_network_info =
                                    self.network_info.write().map_err(|_| crate::Error::PoisonError)?;
                                client_network_info.local_pow = false;
                                msg
                            }
                            Err(e) => {
                                // reset local PoW state
                                let mut client_network_info =
                                    self.network_info.write().map_err(|_| crate::Error::PoisonError)?;
                                client_network_info.local_pow = false;
                                return Err(e);
                            }
                        };
                        let message_dto = MessageDto::from(&message_with_local_pow);

                        self.node_manager
                            .post_request_json(path, timeout, serde_json::to_value(message_dto)?, true)
                            .await?
                    } else {
                        return Err(Error::NodeError(e));
                    }
                } else {
                    return Err(e);
                }
            }
        };

        let mut message_id_bytes = [0u8; 32];
        hex::decode_to_slice(resp.data.message_id, &mut message_id_bytes)?;
        Ok(MessageId::from(message_id_bytes))
    }
/// POST JSON to /api/v1/messages endpoint
POST JSON to /api/v1/messages endpoint
POST JSON to / api / v1 / messages endpoint
pub async fn post_message_json(&self, message: &Message) -> Result<MessageId> {
        let path = "api/v1/messages";
        let local_pow = self.get_local_pow().await;
        let timeout = if local_pow {
            self.get_timeout(Api::PostMessage)
        } else {
            self.get_timeout(Api::PostMessageWithRemotePow)
        };
        let message_dto = MessageDto::from(message);
        // fallback to local PoW if remote PoW fails
        let resp: SuccessBody<SubmitMessageResponse> = match self
            .node_manager
            .post_request_json(path, timeout, serde_json::to_value(message_dto)?, local_pow)
            .await
        {
            Ok(res) => res,
            Err(e) => {
                if let Error::NodeError(e) = e {
                    // hornet and bee return different error messages
                    if e == *"No available nodes with remote PoW"
                        || e.contains("proof of work is not enabled")
                        || e.contains("`PoW` not enabled")
                    {
                        let mut client_network_info =
                            self.network_info.write().map_err(|_| crate::Error::PoisonError)?;
                        // switch to local PoW
                        client_network_info.local_pow = true;
                        drop(client_network_info);
                        #[cfg(not(feature = "wasm"))]
                        let msg_res = crate::api::finish_pow(self, message.payload().clone()).await;
                        #[cfg(feature = "wasm")]
                        let msg_res = {
                            let min_pow_score = self.get_min_pow_score().await?;
                            let network_id = self.get_network_id().await?;
                            crate::api::finish_single_thread_pow(
                                self,
                                network_id,
                                None,
                                message.payload().clone(),
                                min_pow_score,
                            )
                            .await
                        };
                        let message_with_local_pow = match msg_res {
                            Ok(msg) => {
                                // reset local PoW state
                                let mut client_network_info =
                                    self.network_info.write().map_err(|_| crate::Error::PoisonError)?;
                                client_network_info.local_pow = false;
                                msg
                            }
                            Err(e) => {
                                // reset local PoW state
                                let mut client_network_info =
                                    self.network_info.write().map_err(|_| crate::Error::PoisonError)?;
                                client_network_info.local_pow = false;
                                return Err(e);
                            }
                        };
                        let message_dto = MessageDto::from(&message_with_local_pow);
                        self.node_manager
                            .post_request_json(path, timeout, serde_json::to_value(message_dto)?, true)
                            .await?
                    } else {
                        return Err(Error::NodeError(e));
                    }
                } else {
                    return Err(e);
                }
            }
        };
        let mut message_id_bytes = [0u8; 32];
        hex::decode_to_slice(resp.data.message_id, &mut message_id_bytes)?;
        Ok(MessageId::from(message_id_bytes))
    }
pub async fn post_message_json ( & self , message : & Message ) -> Result < MessageId > { let path = " " ; let local_pow = self . get_local_pow ( ) . await ; let timeout = if local_pow { self . get_timeout ( Api :: PostMessage ) } else { self . get_timeout ( Api :: PostMessageWithRemotePow ) } ; let message_dto = MessageDto :: from ( message ) ; // fallback to local PoW if remote PoW fails let resp : SuccessBody < SubmitMessageResponse > = match self . node_manager . post_request_json ( path , timeout , serde_json :: to_value ( message_dto ) ? , local_pow ) . await { Ok ( res ) => res , Err ( e ) => { if let Error :: NodeError ( e ) = e { // hornet and bee return different error messages if e == * " " || e . contains ( " " ) || e . contains ( " " ) { let mut client_network_info = self . network_info . write ( ) . map_err ( | _ | crate :: Error :: PoisonError ) ? ; // switch to local PoW client_network_info . local_pow = true ; drop ( client_network_info ) ; # [ cfg ( not ( feature " " ) ) ] let msg_res = crate :: api :: finish_pow ( self , message . payload ( ) . clone ( ) ) . await ; # [ cfg ( feature " " ) ] let msg_res = { let min_pow_score = self . get_min_pow_score ( ) . await ? ; let network_id = self . get_network_id ( ) . await ? ; crate :: api :: finish_single_thread_pow ( self , network_id , None , message . payload ( ) . clone ( ) , min_pow_score , ) . await } ; let message_with_local_pow = match msg_res { Ok ( msg ) => { // reset local PoW state let mut client_network_info = self . network_info . write ( ) . map_err ( | _ | crate :: Error :: PoisonError ) ? ; client_network_info . local_pow = false ; msg } Err ( e ) => { // reset local PoW state let mut client_network_info = self . network_info . write ( ) . map_err ( | _ | crate :: Error :: PoisonError ) ? ; client_network_info . local_pow = false ; return Err ( e ) ; } } ; let message_dto = MessageDto :: from ( & message_with_local_pow ) ; self . node_manager . post_request_json ( path , timeout , serde_json :: to_value ( message_dto ) ? , true ) . await ? } else { return Err ( Error :: NodeError ( e ) ) ; } } else { return Err ( e ) ; } } } ; let mut message_id_bytes = [ 0u8 ; 32 ] ; hex :: decode_to_slice ( resp . data . message_id , & mut message_id_bytes ) ? ; Ok ( MessageId :: from ( message_id_bytes ) ) }
POST JSON to /api/v1/messages endpoint
POST JSON to / api / v1 / messages endpoint
&self
message
&Message
&self
message
&Message