fn simulate_transactions(
    rpc_client: &RpcClient,
    candidate_transactions: Vec<(Transaction, String)>,
) -> client_error::Result<Vec<(Transaction, String)>> {
    let (blockhash, _fee_calculator) = rpc_client.get_recent_blockhash()?;

    info!(
        "Simulating {} transactions with blockhash {}",
        candidate_transactions.len(),
        blockhash
    );
    let mut simulated_transactions = vec![];
    for (mut transaction, memo) in candidate_transactions {
        transaction.message.recent_blockhash = blockhash;

        let sim_result = rpc_client.simulate_transaction_with_config(
            &transaction,
            RpcSimulateTransactionConfig {
                sig_verify: false,
                ..RpcSimulateTransactionConfig::default()
            },
        )?;
        if sim_result.value.err.is_some() {
            trace!(
                "filtering out transaction due to simulation failure: {:?}: {}",
                sim_result,
                memo
            );
        } else {
            simulated_transactions.push((transaction, memo))
        }
    }
    info!(
        "Successfully simulating {} transactions",
        simulated_transactions.len()
    );
    Ok(simulated_transactions)
}
/// Simulate a list of transactions and filter out the ones that will fail
Simulate a list of transactions and filter out the ones that will fail
Simulate a list of transactions and filter out the ones that will fail
fn simulate_transactions(
    rpc_client: &RpcClient,
    candidate_transactions: Vec<(Transaction, String)>,
) -> client_error::Result<Vec<(Transaction, String)>> {
    let (blockhash, _fee_calculator) = rpc_client.get_recent_blockhash()?;
    info!(
        "Simulating {} transactions with blockhash {}",
        candidate_transactions.len(),
        blockhash
    );
    let mut simulated_transactions = vec![];
    for (mut transaction, memo) in candidate_transactions {
        transaction.message.recent_blockhash = blockhash;
        let sim_result = rpc_client.simulate_transaction_with_config(
            &transaction,
            RpcSimulateTransactionConfig {
                sig_verify: false,
                ..RpcSimulateTransactionConfig::default()
            },
        )?;
        if sim_result.value.err.is_some() {
            trace!(
                "filtering out transaction due to simulation failure: {:?}: {}",
                sim_result,
                memo
            );
        } else {
            simulated_transactions.push((transaction, memo))
        }
    }
    info!(
        "Successfully simulating {} transactions",
        simulated_transactions.len()
    );
    Ok(simulated_transactions)
}
fn simulate_transactions ( rpc_client : & RpcClient , candidate_transactions : Vec < ( Transaction , String ) > , ) -> client_error :: Result < Vec < ( Transaction , String ) > > { let ( blockhash , _fee_calculator ) = rpc_client . get_recent_blockhash ( ) ? ; info ! ( " " candidate_transactions len ( ) blockhash ) ; let mut simulated_transactions = vec ! [ ] ; for ( mut transaction , memo ) in candidate_transactions { transaction . message . recent_blockhash = blockhash ; let sim_result = rpc_client . simulate_transaction_with_config ( & transaction , RpcSimulateTransactionConfig { sig_verify : false , .. RpcSimulateTransactionConfig :: default ( ) } , ) ? ; if sim_result . value . err . is_some ( ) { trace ! ( " " sim_result memo ) ; } else { simulated_transactions . push ( ( transaction , memo ) ) } } info ! ( " " simulated_transactions len ( ) ) ; Ok ( simulated_transactions ) }
Simulate a list of transactions and filter out the ones that will fail
Simulate a list of transactions and filter out the ones that will fail
rpc_client
&RpcClient
candidate_transactions
Vec<(Transaction, String)>
rpc_client
&RpcClient
candidate_transactions
Vec<(Transaction, String)>