pub async fn wait_for_transaction(
        &self,
        tx_hash: Uint256,
        timeout: Duration,
        blocks_to_wait: Option<Uint256>,
    ) -> Result<TransactionResponse, Web3Error> {
        let start = Instant::now();
        loop {
            delay_for(Duration::from_secs(1)).await;
            match self.eth_get_transaction_by_hash(tx_hash.clone()).await {
                Ok(maybe_transaction) => {
                    if let Some(transaction) = maybe_transaction {
                        // if no wait time is specified and the tx is in a block return right away
                        if blocks_to_wait.clone().is_none() && transaction.block_number.is_some() {
                            return Ok(transaction);
                        }
                        // One the tx is in a block we start waiting here
                        else if let (Some(blocks_to_wait), Some(tx_block)) =
                            (blocks_to_wait.clone(), transaction.block_number.clone())
                        {
                            let current_block = self.eth_block_number().await?;
                            // we check for underflow, which is possible on testnets
                            if current_block > blocks_to_wait
                                && current_block - blocks_to_wait >= tx_block
                            {
                                return Ok(transaction);
                            }
                        }
                    }
                }
                Err(e) => return Err(e),
            }

            if Instant::now() - start > timeout {
                return Err(Web3Error::TransactionTimeout);
            }
        }
    }
/// Waits for a transaction with the given hash to be included in a block
/// it will wait for at most timeout time and optionally can wait for n
/// blocks to have passed
Waits for a transaction with the given hash to be included in a block
it will wait for at most timeout time and optionally can wait for n
blocks to have passed
Waits for a transaction with the given hash to be included in a block it will wait for at most timeout time and optionally can wait for n blocks to have passed
pub async fn wait_for_transaction(
        &self,
        tx_hash: Uint256,
        timeout: Duration,
        blocks_to_wait: Option<Uint256>,
    ) -> Result<TransactionResponse, Web3Error> {
        let start = Instant::now();
        loop {
            delay_for(Duration::from_secs(1)).await;
            match self.eth_get_transaction_by_hash(tx_hash.clone()).await {
                Ok(maybe_transaction) => {
                    if let Some(transaction) = maybe_transaction {
                        // if no wait time is specified and the tx is in a block return right away
                        if blocks_to_wait.clone().is_none() && transaction.block_number.is_some() {
                            return Ok(transaction);
                        }
                        // One the tx is in a block we start waiting here
                        else if let (Some(blocks_to_wait), Some(tx_block)) =
                            (blocks_to_wait.clone(), transaction.block_number.clone())
                        {
                            let current_block = self.eth_block_number().await?;
                            // we check for underflow, which is possible on testnets
                            if current_block > blocks_to_wait
                                && current_block - blocks_to_wait >= tx_block
                            {
                                return Ok(transaction);
                            }
                        }
                    }
                }
                Err(e) => return Err(e),
            }
            if Instant::now() - start > timeout {
                return Err(Web3Error::TransactionTimeout);
            }
        }
    }
pub async fn wait_for_transaction ( & self , tx_hash : Uint256 , timeout : Duration , blocks_to_wait : Option < Uint256 > , ) -> Result < TransactionResponse , Web3Error > { let start = Instant :: now ( ) ; loop { delay_for ( Duration :: from_secs ( 1 ) ) . await ; match self . eth_get_transaction_by_hash ( tx_hash . clone ( ) ) . await { Ok ( maybe_transaction ) => { if let Some ( transaction ) = maybe_transaction { // if no wait time is specified and the tx is in a block return right away if blocks_to_wait . clone ( ) . is_none ( ) && transaction . block_number . is_some ( ) { return Ok ( transaction ) ; } // One the tx is in a block we start waiting here else if let ( Some ( blocks_to_wait ) , Some ( tx_block ) ) = ( blocks_to_wait . clone ( ) , transaction . block_number . clone ( ) ) { let current_block = self . eth_block_number ( ) . await ? ; // we check for underflow, which is possible on testnets if current_block > blocks_to_wait && current_block - blocks_to_wait >= tx_block { return Ok ( transaction ) ; } } } } Err ( e ) => return Err ( e ) , } if Instant :: now ( ) - start > timeout { return Err ( Web3Error :: TransactionTimeout ) ; } } }
Waits for a transaction with the given hash to be included in a block
it will wait for at most timeout time and optionally can wait for n
blocks to have passed
Waits for a transaction with the given hash to be included in a block it will wait for at most timeout time and optionally can wait for n blocks to have passed
&self
tx_hash
Uint256
timeout
Duration
blocks_to_wait
Option<Uint256>
&self
tx_hash
Uint256
timeout
Duration
blocks_to_wait
Option<Uint256>