pub async fn wait_for_transaction(
        &self,
        transaction_identifier: &TransactionIdentifier,
        mut prev_chain_length: BlockHeight,
        deadline: std::time::Instant,
    ) -> Result<Option<BlockHeight>, ApiError> {
        debug!(
            "Waiting for transaction {:?} to appear...",
            transaction_identifier
        );

        loop {
            let cur_chain_length = self
                .ledger
                .read_blocks()
                .await
                .last_verified()?
                .map(|hb| hb.index + 1)
                .unwrap_or(0);

            for idx in prev_chain_length..cur_chain_length {
                debug!("Looking at block {}", idx);
                let blocks = self.ledger.read_blocks().await;
                let hb = get_block(
                    &blocks,
                    Some(PartialBlockIdentifier {
                        index: Some(idx as i64),
                        hash: None,
                    }),
                )?;
                let block = hb.block.decode().map_err(|err| {
                    ApiError::internal_error(format!("Cannot decode block: {}", err))
                })?;
                let hash = block.transaction.hash();
                if TransactionIdentifier::from(&hash) == *transaction_identifier {
                    return Ok(Some(idx));
                }
            }

            prev_chain_length = cur_chain_length;

            if Instant::now() > deadline {
                break;
            }
            tokio::time::sleep(Duration::from_secs(1)).await;
        }

        warn!(
            "Transaction {:?} did not appear within the deadline",
            transaction_identifier
        );

        Ok(None)
    }
/// Wait until a new block appears that contains the specified
/// transaction.
Wait until a new block appears that contains the specified
transaction.
Wait until a new block appears that contains the specified transaction .
pub async fn wait_for_transaction(
        &self,
        transaction_identifier: &TransactionIdentifier,
        mut prev_chain_length: BlockHeight,
        deadline: std::time::Instant,
    ) -> Result<Option<BlockHeight>, ApiError> {
        debug!(
            "Waiting for transaction {:?} to appear...",
            transaction_identifier
        );
        loop {
            let cur_chain_length = self
                .ledger
                .read_blocks()
                .await
                .last_verified()?
                .map(|hb| hb.index + 1)
                .unwrap_or(0);
            for idx in prev_chain_length..cur_chain_length {
                debug!("Looking at block {}", idx);
                let blocks = self.ledger.read_blocks().await;
                let hb = get_block(
                    &blocks,
                    Some(PartialBlockIdentifier {
                        index: Some(idx as i64),
                        hash: None,
                    }),
                )?;
                let block = hb.block.decode().map_err(|err| {
                    ApiError::internal_error(format!("Cannot decode block: {}", err))
                })?;
                let hash = block.transaction.hash();
                if TransactionIdentifier::from(&hash) == *transaction_identifier {
                    return Ok(Some(idx));
                }
            }
            prev_chain_length = cur_chain_length;
            if Instant::now() > deadline {
                break;
            }
            tokio::time::sleep(Duration::from_secs(1)).await;
        }
        warn!(
            "Transaction {:?} did not appear within the deadline",
            transaction_identifier
        );
        Ok(None)
    }
pub async fn wait_for_transaction ( & self , transaction_identifier : & TransactionIdentifier , mut prev_chain_length : BlockHeight , deadline : std :: time :: Instant , ) -> Result < Option < BlockHeight > , ApiError > { debug ! ( " " transaction_identifier ) ; loop { let cur_chain_length = self . ledger . read_blocks ( ) . await . last_verified ( ) ? . map ( | hb | hb . index + 1 ) . unwrap_or ( 0 ) ; for idx in prev_chain_length .. cur_chain_length { debug ! ( " " idx ) ; let blocks = self . ledger . read_blocks ( ) . await ; let hb = get_block ( & blocks , Some ( PartialBlockIdentifier { index : Some ( idx as i64 ) , hash : None , } ) , ) ? ; let block = hb . block . decode ( ) . map_err ( | err | { ApiError :: internal_error ( format ! ( " " err ) ) } ) ? ; let hash = block . transaction . hash ( ) ; if TransactionIdentifier :: from ( & hash ) == * transaction_identifier { return Ok ( Some ( idx ) ) ; } } prev_chain_length = cur_chain_length ; if Instant :: now ( ) > deadline { break ; } tokio :: time :: sleep ( Duration :: from_secs ( 1 ) ) . await ; } warn ! ( " " transaction_identifier ) ; Ok ( None ) }
Wait until a new block appears that contains the specified
transaction.
Wait until a new block appears that contains the specified transaction .
&self
transaction_identifier
&TransactionIdentifier
prev_chain_length
BlockHeight
deadline
std::time::Instant
&self
transaction_identifier
&TransactionIdentifier
prev_chain_length
BlockHeight
deadline
std::time::Instant