pub fn send_and_confirm_transaction<T: Signers>(
        &self,
        keypairs: &T,
        transaction: &mut Transaction,
        tries: usize,
        pending_confirmations: usize,
    ) -> TransportResult<Signature> {
        for x in 0..tries {
            let now = Instant::now();
            let mut buf = vec![0; serialized_size(&transaction).unwrap() as usize];
            let mut wr = std::io::Cursor::new(&mut buf[..]);
            let mut num_confirmed = 0;
            let mut wait_time = MAX_PROCESSING_AGE;
            serialize_into(&mut wr, &transaction)
                .expect("serialize Transaction in pub fn transfer_signed");
            // resend the same transaction until the transaction has no chance of succeeding
            while now.elapsed().as_secs() < wait_time as u64 {
                if num_confirmed == 0 {
                    // Send the transaction if there has been no confirmation (e.g. the first time)
                    self.transactions_socket
                        .send_to(&buf[..], &self.tpu_addr())?;
                }

                if let Ok(confirmed_blocks) = self.poll_for_signature_confirmation(
                    &transaction.signatures[0],
                    pending_confirmations,
                ) {
                    num_confirmed = confirmed_blocks;
                    if confirmed_blocks >= pending_confirmations {
                        return Ok(transaction.signatures[0]);
                    }
                    // Since network has seen the transaction, wait longer to receive
                    // all pending confirmations. Resending the transaction could result into
                    // extra transaction fees
                    wait_time = wait_time.max(
                        MAX_PROCESSING_AGE * pending_confirmations.saturating_sub(num_confirmed),
                    );
                }
            }
            info!("{} tries failed transfer to {}", x, self.tpu_addr());
            let blockhash = self.get_latest_blockhash()?;
            transaction.sign(keypairs, blockhash);
        }
        Err(io::Error::new(
            io::ErrorKind::Other,
            format!("retry_transfer failed in {} retries", tries),
        )
        .into())
    }
/// Retry sending a signed Transaction to the server for processing
Retry sending a signed Transaction to the server for processing
Retry sending a signed Transaction to the server for processing
pub fn send_and_confirm_transaction<T: Signers>(
        &self,
        keypairs: &T,
        transaction: &mut Transaction,
        tries: usize,
        pending_confirmations: usize,
    ) -> TransportResult<Signature> {
        for x in 0..tries {
            let now = Instant::now();
            let mut buf = vec![0; serialized_size(&transaction).unwrap() as usize];
            let mut wr = std::io::Cursor::new(&mut buf[..]);
            let mut num_confirmed = 0;
            let mut wait_time = MAX_PROCESSING_AGE;
            serialize_into(&mut wr, &transaction)
                .expect("serialize Transaction in pub fn transfer_signed");
            // resend the same transaction until the transaction has no chance of succeeding
            while now.elapsed().as_secs() < wait_time as u64 {
                if num_confirmed == 0 {
                    // Send the transaction if there has been no confirmation (e.g. the first time)
                    self.transactions_socket
                        .send_to(&buf[..], &self.tpu_addr())?;
                }
                if let Ok(confirmed_blocks) = self.poll_for_signature_confirmation(
                    &transaction.signatures[0],
                    pending_confirmations,
                ) {
                    num_confirmed = confirmed_blocks;
                    if confirmed_blocks >= pending_confirmations {
                        return Ok(transaction.signatures[0]);
                    }
                    // Since network has seen the transaction, wait longer to receive
                    // all pending confirmations. Resending the transaction could result into
                    // extra transaction fees
                    wait_time = wait_time.max(
                        MAX_PROCESSING_AGE * pending_confirmations.saturating_sub(num_confirmed),
                    );
                }
            }
            info!("{} tries failed transfer to {}", x, self.tpu_addr());
            let blockhash = self.get_latest_blockhash()?;
            transaction.sign(keypairs, blockhash);
        }
        Err(io::Error::new(
            io::ErrorKind::Other,
            format!("retry_transfer failed in {} retries", tries),
        )
        .into())
    }
pub fn send_and_confirm_transaction < T : Signers > ( & self , keypairs : & T , transaction : & mut Transaction , tries : usize , pending_confirmations : usize , ) -> TransportResult < Signature > { for x in 0 .. tries { let now = Instant :: now ( ) ; let mut buf = vec ! [ 0 serialized_size ( transaction ) unwrap ( ) as usize ] ; let mut wr = std :: io :: Cursor :: new ( & mut buf [ .. ] ) ; let mut num_confirmed = 0 ; let mut wait_time = MAX_PROCESSING_AGE ; serialize_into ( & mut wr , & transaction ) . expect ( " " ) ; // resend the same transaction until the transaction has no chance of succeeding while now . elapsed ( ) . as_secs ( ) < wait_time as u64 { if num_confirmed == 0 { // Send the transaction if there has been no confirmation (e.g. the first time) self . transactions_socket . send_to ( & buf [ .. ] , & self . tpu_addr ( ) ) ? ; } if let Ok ( confirmed_blocks ) = self . poll_for_signature_confirmation ( & transaction . signatures [ 0 ] , pending_confirmations , ) { num_confirmed = confirmed_blocks ; if confirmed_blocks >= pending_confirmations { return Ok ( transaction . signatures [ 0 ] ) ; } // Since network has seen the transaction, wait longer to receive // all pending confirmations. Resending the transaction could result into // extra transaction fees wait_time = wait_time . max ( MAX_PROCESSING_AGE * pending_confirmations . saturating_sub ( num_confirmed ) , ) ; } } info ! ( " " x self tpu_addr ( ) ) ; let blockhash = self . get_latest_blockhash ( ) ? ; transaction . sign ( keypairs , blockhash ) ; } Err ( io :: Error :: new ( io :: ErrorKind :: Other , format ! ( " " tries ) , ) . into ( ) ) }
Retry sending a signed Transaction to the server for processing
Retry sending a signed Transaction to the server for processing
&self
keypairs
&T
transaction
&mut Transaction
tries
usize
pending_confirmations
usize