pub fn fund_keys<T: 'static + Client + Send + Sync>(
    client: Arc<T>,
    source: &Keypair,
    dests: &[Keypair],
    total: u64,
    max_fee: u64,
    lamports_per_account: u64,
) {
    let mut funded: Vec<&Keypair> = vec![source];
    let mut funded_funds = total;
    let mut not_funded: Vec<&Keypair> = dests.iter().collect();
    while !not_funded.is_empty() {
        // Build to fund list and prepare funding sources for next iteration
        let mut new_funded: Vec<&Keypair> = vec![];
        let mut to_fund: Vec<(&Keypair, Vec<(Pubkey, u64)>)> = vec![];
        let to_lamports = (funded_funds - lamports_per_account - max_fee) / MAX_SPENDS_PER_TX;
        for f in funded {
            let start = not_funded.len() - MAX_SPENDS_PER_TX as usize;
            let dests: Vec<_> = not_funded.drain(start..).collect();
            let spends: Vec<_> = dests.iter().map(|k| (k.pubkey(), to_lamports)).collect();
            to_fund.push((f, spends));
            new_funded.extend(dests.into_iter());
        }

        // try to transfer a "few" at a time with recent blockhash
        //  assume 4MB network buffers, and 512 byte packets
        const FUND_CHUNK_LEN: usize = 4 * 1024 * 1024 / 512;

        to_fund.chunks(FUND_CHUNK_LEN).for_each(|chunk| {
            Vec::<(&Keypair, Transaction)>::with_capacity(chunk.len()).fund(
                &client,
                chunk,
                to_lamports,
            );
        });

        info!("funded: {} left: {}", new_funded.len(), not_funded.len());
        funded = new_funded;
        funded_funds = to_lamports;
    }
}
/// fund the dests keys by spending all of the source keys into MAX_SPENDS_PER_TX
/// on every iteration.  This allows us to replay the transfers because the source is either empty,
/// or full
fund the dests keys by spending all of the source keys into MAX_SPENDS_PER_TX
on every iteration.  This allows us to replay the transfers because the source is either empty,
or full
fund the dests keys by spending all of the source keys into MAX_SPENDS_PER_TX on every iteration . This allows us to replay the transfers because the source is either empty or full
pub fn fund_keys<T: 'static + Client + Send + Sync>(
    client: Arc<T>,
    source: &Keypair,
    dests: &[Keypair],
    total: u64,
    max_fee: u64,
    lamports_per_account: u64,
) {
    let mut funded: Vec<&Keypair> = vec![source];
    let mut funded_funds = total;
    let mut not_funded: Vec<&Keypair> = dests.iter().collect();
    while !not_funded.is_empty() {
        // Build to fund list and prepare funding sources for next iteration
        let mut new_funded: Vec<&Keypair> = vec![];
        let mut to_fund: Vec<(&Keypair, Vec<(Pubkey, u64)>)> = vec![];
        let to_lamports = (funded_funds - lamports_per_account - max_fee) / MAX_SPENDS_PER_TX;
        for f in funded {
            let start = not_funded.len() - MAX_SPENDS_PER_TX as usize;
            let dests: Vec<_> = not_funded.drain(start..).collect();
            let spends: Vec<_> = dests.iter().map(|k| (k.pubkey(), to_lamports)).collect();
            to_fund.push((f, spends));
            new_funded.extend(dests.into_iter());
        }
        // try to transfer a "few" at a time with recent blockhash
        //  assume 4MB network buffers, and 512 byte packets
        const FUND_CHUNK_LEN: usize = 4 * 1024 * 1024 / 512;
        to_fund.chunks(FUND_CHUNK_LEN).for_each(|chunk| {
            Vec::<(&Keypair, Transaction)>::with_capacity(chunk.len()).fund(
                &client,
                chunk,
                to_lamports,
            );
        });
        info!("funded: {} left: {}", new_funded.len(), not_funded.len());
        funded = new_funded;
        funded_funds = to_lamports;
    }
}
pub fn fund_keys < T : ' static + Client + Send + Sync > ( client : Arc < T > , source : & Keypair , dests : & [ Keypair ] , total : u64 , max_fee : u64 , lamports_per_account : u64 , ) { let mut funded : Vec < & Keypair > = vec ! [ source ] ; let mut funded_funds = total ; let mut not_funded : Vec < & Keypair > = dests . iter ( ) . collect ( ) ; while ! not_funded . is_empty ( ) { // Build to fund list and prepare funding sources for next iteration let mut new_funded : Vec < & Keypair > = vec ! [ ] ; let mut to_fund : Vec < ( & Keypair , Vec < ( Pubkey , u64 ) > ) > = vec ! [ ] ; let to_lamports = ( funded_funds - lamports_per_account - max_fee ) / MAX_SPENDS_PER_TX ; for f in funded { let start = not_funded . len ( ) - MAX_SPENDS_PER_TX as usize ; let dests : Vec < _ > = not_funded . drain ( start .. ) . collect ( ) ; let spends : Vec < _ > = dests . iter ( ) . map ( | k | ( k . pubkey ( ) , to_lamports ) ) . collect ( ) ; to_fund . push ( ( f , spends ) ) ; new_funded . extend ( dests . into_iter ( ) ) ; } // try to transfer a "few" at a time with recent blockhash //  assume 4MB network buffers, and 512 byte packets const FUND_CHUNK_LEN : usize = 4 * 1024 * 1024 / 512 ; to_fund . chunks ( FUND_CHUNK_LEN ) . for_each ( | chunk | { Vec :: < ( & Keypair , Transaction ) > :: with_capacity ( chunk . len ( ) ) . fund ( & client , chunk , to_lamports , ) ; } ) ; info ! ( " " new_funded len ( ) not_funded len ( ) ) ; funded = new_funded ; funded_funds = to_lamports ; } }
fund the dests keys by spending all of the source keys into MAX_SPENDS_PER_TX
on every iteration.
fund the dests keys by spending all of the source keys into MAX_SPENDS_PER_TX on every iteration .
client
Arc<T>
source
&Keypair
dests
&[Keypair]
total
u64
max_fee
u64
lamports_per_account
u64