pub async fn retry_until_included(
        &self,
        message_id: &MessageId,
        interval: Option<u64>,
        max_attempts: Option<u64>,
    ) -> Result<Vec<(MessageId, Message)>> {
        // Attachments of the Message to check inclusion state
        let mut message_ids = vec![*message_id];
        // Reattached Messages that get returned
        let mut messages_with_id = Vec::new();
        for _ in 0..max_attempts.unwrap_or(40) {
            #[cfg(feature = "wasm")]
            {
                use wasm_timer::Delay;
                Delay::new(Duration::from_secs(interval.unwrap_or(5))).await?;
            }
            #[cfg(not(feature = "wasm"))]
            sleep(Duration::from_secs(interval.unwrap_or(5))).await;
            // Check inclusion state for each attachment
            let message_ids_len = message_ids.len();
            let mut conflicting = false;
            for (index, msg_id) in message_ids.clone().iter().enumerate() {
                let message_metadata = self.get_message().metadata(msg_id).await?;
                if let Some(inclusion_state) = message_metadata.ledger_inclusion_state {
                    match inclusion_state {
                        LedgerInclusionStateDto::Included | LedgerInclusionStateDto::NoTransaction => {
                            // if original message, request it so we can return it on first position
                            if message_id == msg_id {
                                let mut included_and_reattached_messages =
                                    vec![(*message_id, self.get_message().data(message_id).await?)];
                                included_and_reattached_messages.extend(messages_with_id);
                                return Ok(included_and_reattached_messages);
                            } else {
                                // Move included message to first position
                                messages_with_id.rotate_left(index);
                                return Ok(messages_with_id);
                            }
                        }
                        // only set it as conflicting here and don't return, because another reattached message could
                        // have the included transaction
                        LedgerInclusionStateDto::Conflicting => conflicting = true,
                    };
                }
                // Only reattach or promote latest attachment of the message
                if index == message_ids_len - 1 {
                    if message_metadata.should_promote.unwrap_or(false) {
                        // Safe to unwrap since we iterate over it
                        self.promote_unchecked(message_ids.last().unwrap()).await?;
                    } else if message_metadata.should_reattach.unwrap_or(false) {
                        // Safe to unwrap since we iterate over it
                        let reattached = self.reattach_unchecked(message_ids.last().unwrap()).await?;
                        message_ids.push(reattached.0);
                        messages_with_id.push(reattached);
                    }
                }
            }
            // After we checked all our reattached messages, check if the transaction got reattached in another message
            // and confirmed
            if conflicting {
                let message = self.get_message().data(message_id).await?;
                if let Some(Payload::Transaction(transaction_payload)) = message.payload() {
                    let included_message = self.get_included_message(&transaction_payload.id()).await?;
                    let mut included_and_reattached_messages = vec![(included_message.id().0, included_message)];
                    included_and_reattached_messages.extend(messages_with_id);
                    return Ok(included_and_reattached_messages);
                }
            }
        }
        Err(Error::TangleInclusionError(message_id.to_string()))
    }
/// Retries (promotes or reattaches) a message for provided message id until it's included (referenced by a
/// milestone). Default interval is 5 seconds and max attempts is 40. Returns the included message at first position
/// and additional reattached messages
Retries (promotes or reattaches) a message for provided message id until it's included (referenced by a
milestone). Default interval is 5 seconds and max attempts is 40. Returns the included message at first position
and additional reattached messages
Retries ( promotes or reattaches ) a message for provided message id until it ' s included ( referenced by a milestone ) . Default interval is 5 seconds and max attempts is 40 . Returns the included message at first position and additional reattached messages
pub async fn retry_until_included(
        &self,
        message_id: &MessageId,
        interval: Option<u64>,
        max_attempts: Option<u64>,
    ) -> Result<Vec<(MessageId, Message)>> {
        // Attachments of the Message to check inclusion state
        let mut message_ids = vec![*message_id];
        // Reattached Messages that get returned
        let mut messages_with_id = Vec::new();
        for _ in 0..max_attempts.unwrap_or(40) {
            #[cfg(feature = "wasm")]
            {
                use wasm_timer::Delay;
                Delay::new(Duration::from_secs(interval.unwrap_or(5))).await?;
            }
            #[cfg(not(feature = "wasm"))]
            sleep(Duration::from_secs(interval.unwrap_or(5))).await;
            // Check inclusion state for each attachment
            let message_ids_len = message_ids.len();
            let mut conflicting = false;
            for (index, msg_id) in message_ids.clone().iter().enumerate() {
                let message_metadata = self.get_message().metadata(msg_id).await?;
                if let Some(inclusion_state) = message_metadata.ledger_inclusion_state {
                    match inclusion_state {
                        LedgerInclusionStateDto::Included | LedgerInclusionStateDto::NoTransaction => {
                            // if original message, request it so we can return it on first position
                            if message_id == msg_id {
                                let mut included_and_reattached_messages =
                                    vec![(*message_id, self.get_message().data(message_id).await?)];
                                included_and_reattached_messages.extend(messages_with_id);
                                return Ok(included_and_reattached_messages);
                            } else {
                                // Move included message to first position
                                messages_with_id.rotate_left(index);
                                return Ok(messages_with_id);
                            }
                        }
                        // only set it as conflicting here and don't return, because another reattached message could
                        // have the included transaction
                        LedgerInclusionStateDto::Conflicting => conflicting = true,
                    };
                }
                // Only reattach or promote latest attachment of the message
                if index == message_ids_len - 1 {
                    if message_metadata.should_promote.unwrap_or(false) {
                        // Safe to unwrap since we iterate over it
                        self.promote_unchecked(message_ids.last().unwrap()).await?;
                    } else if message_metadata.should_reattach.unwrap_or(false) {
                        // Safe to unwrap since we iterate over it
                        let reattached = self.reattach_unchecked(message_ids.last().unwrap()).await?;
                        message_ids.push(reattached.0);
                        messages_with_id.push(reattached);
                    }
                }
            }
            // After we checked all our reattached messages, check if the transaction got reattached in another message
            // and confirmed
            if conflicting {
                let message = self.get_message().data(message_id).await?;
                if let Some(Payload::Transaction(transaction_payload)) = message.payload() {
                    let included_message = self.get_included_message(&transaction_payload.id()).await?;
                    let mut included_and_reattached_messages = vec![(included_message.id().0, included_message)];
                    included_and_reattached_messages.extend(messages_with_id);
                    return Ok(included_and_reattached_messages);
                }
            }
        }
        Err(Error::TangleInclusionError(message_id.to_string()))
    }
pub async fn retry_until_included ( & self , message_id : & MessageId , interval : Option < u64 > , max_attempts : Option < u64 > , ) -> Result < Vec < ( MessageId , Message ) > > { // Attachments of the Message to check inclusion state let mut message_ids = vec ! [ message_id ] ; // Reattached Messages that get returned let mut messages_with_id = Vec :: new ( ) ; for _ in 0 .. max_attempts . unwrap_or ( 40 ) { # [ cfg ( feature " " ) ] { use wasm_timer :: Delay ; Delay :: new ( Duration :: from_secs ( interval . unwrap_or ( 5 ) ) ) . await ? ; } # [ cfg ( not ( feature " " ) ) ] sleep ( Duration :: from_secs ( interval . unwrap_or ( 5 ) ) ) . await ; // Check inclusion state for each attachment let message_ids_len = message_ids . len ( ) ; let mut conflicting = false ; for ( index , msg_id ) in message_ids . clone ( ) . iter ( ) . enumerate ( ) { let message_metadata = self . get_message ( ) . metadata ( msg_id ) . await ? ; if let Some ( inclusion_state ) = message_metadata . ledger_inclusion_state { match inclusion_state { LedgerInclusionStateDto :: Included | LedgerInclusionStateDto :: NoTransaction => { // if original message, request it so we can return it on first position if message_id == msg_id { let mut included_and_reattached_messages = vec ! [ ( message_id self get_message ( ) data ( message_id ) await ) ] ; included_and_reattached_messages . extend ( messages_with_id ) ; return Ok ( included_and_reattached_messages ) ; } else { // Move included message to first position messages_with_id . rotate_left ( index ) ; return Ok ( messages_with_id ) ; } } // only set it as conflicting here and don't return, because another reattached message could // have the included transaction LedgerInclusionStateDto :: Conflicting => conflicting = true , } ; } // Only reattach or promote latest attachment of the message if index == message_ids_len - 1 { if message_metadata . should_promote . unwrap_or ( false ) { // Safe to unwrap since we iterate over it self . promote_unchecked ( message_ids . last ( ) . unwrap ( ) ) . await ? ; } else if message_metadata . should_reattach . unwrap_or ( false ) { // Safe to unwrap since we iterate over it let reattached = self . reattach_unchecked ( message_ids . last ( ) . unwrap ( ) ) . await ? ; message_ids . push ( reattached . 0 ) ; messages_with_id . push ( reattached ) ; } } } // After we checked all our reattached messages, check if the transaction got reattached in another message // and confirmed if conflicting { let message = self . get_message ( ) . data ( message_id ) . await ? ; if let Some ( Payload :: Transaction ( transaction_payload ) ) = message . payload ( ) { let included_message = self . get_included_message ( & transaction_payload . id ( ) ) . await ? ; let mut included_and_reattached_messages = vec ! [ ( included_message id ( ) 0 included_message ) ] ; included_and_reattached_messages . extend ( messages_with_id ) ; return Ok ( included_and_reattached_messages ) ; } } } Err ( Error :: TangleInclusionError ( message_id . to_string ( ) ) ) }
Retries (promotes or reattaches) a message for provided message id until it's included (referenced by a
milestone).
Retries ( promotes or reattaches ) a message for provided message id until it ' s included ( referenced by a milestone ) .
&self
message_id
&MessageId
interval
Option<u64>
max_attempts
Option<u64>
&self
message_id
&MessageId
interval
Option<u64>
max_attempts
Option<u64>