pub fn fund_keys<T: Client>(client: &T, source: &Keypair, dests: &[Keypair], difs: u64) {
    let total = difs * dests.len() as u64;
    let mut funded: Vec<(&Keypair, u64)> = vec![(source, total)];
    let mut notfunded: Vec<&Keypair> = dests.iter().collect();

    println!("funding keys {}", dests.len());
    while !notfunded.is_empty() {
        let mut new_funded: Vec<(&Keypair, u64)> = vec![];
        let mut to_fund = vec![];
        println!("creating from... {}", funded.len());
        for f in &mut funded {
            let max_units = cmp::min(notfunded.len(), MAX_SPENDS_PER_TX);
            if max_units == 0 {
                break;
            }
            let start = notfunded.len() - max_units;
            let per_unit = f.1 / (max_units as u64);
            let moves: Vec<_> = notfunded[start..]
                .iter()
                .map(|k| (k.pubkey(), per_unit))
                .collect();
            notfunded[start..]
                .iter()
                .for_each(|k| new_funded.push((k, per_unit)));
            notfunded.truncate(start);
            if !moves.is_empty() {
                to_fund.push((f.0, moves));
            }
        }

        // 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| {
            let mut tries = 0;

            // this set of transactions just initializes us for bookkeeping
            #[allow(clippy::clone_double_ref)] // sigh
            let mut to_fund_txs: Vec<_> = chunk
                .par_iter()
                .map(|(k, m)| {
                    (
                        k.clone(),
                        Transaction::new_unsigned_instructions(system_instruction::transfer_many(
                            &k.pubkey(),
                            &m,
                        )),
                    )
                })
                .collect();

            let amount = chunk[0].1[0].1;

            while !to_fund_txs.is_empty() {
                let receivers = to_fund_txs
                    .iter()
                    .fold(0, |len, (_, tx)| len + tx.message().instructions.len());

                println!(
                    "{} {} to {} in {} txs",
                    if tries == 0 {
                        "transferring"
                    } else {
                        " retrying"
                    },
                    amount,
                    receivers,
                    to_fund_txs.len(),
                );

                let (blockhash, _fee_calculator) = client.get_recent_blockhash().unwrap();

                // re-sign retained to_fund_txes with updated blockhash
                to_fund_txs.par_iter_mut().for_each(|(k, tx)| {
                    tx.sign(&[*k], blockhash);
                });

                to_fund_txs.iter().for_each(|(_, tx)| {
                    client.async_send_transaction(tx.clone()).expect("transfer");
                });

                // retry anything that seems to have dropped through cracks
                //  again since these txs are all or nothing, they're fine to
                //  retry
                for _ in 0..10 {
                    to_fund_txs.retain(|(_, tx)| !verify_funding_transfer(client, &tx, amount));
                    if to_fund_txs.is_empty() {
                        break;
                    }
                    sleep(Duration::from_millis(100));
                }

                tries += 1;
            }
            println!("transferred");
        });
        println!("funded: {} left: {}", new_funded.len(), notfunded.len());
        funded = new_funded;
    }
}
/// 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: Client>(client: &T, source: &Keypair, dests: &[Keypair], difs: u64) {
    let total = difs * dests.len() as u64;
    let mut funded: Vec<(&Keypair, u64)> = vec![(source, total)];
    let mut notfunded: Vec<&Keypair> = dests.iter().collect();
    println!("funding keys {}", dests.len());
    while !notfunded.is_empty() {
        let mut new_funded: Vec<(&Keypair, u64)> = vec![];
        let mut to_fund = vec![];
        println!("creating from... {}", funded.len());
        for f in &mut funded {
            let max_units = cmp::min(notfunded.len(), MAX_SPENDS_PER_TX);
            if max_units == 0 {
                break;
            }
            let start = notfunded.len() - max_units;
            let per_unit = f.1 / (max_units as u64);
            let moves: Vec<_> = notfunded[start..]
                .iter()
                .map(|k| (k.pubkey(), per_unit))
                .collect();
            notfunded[start..]
                .iter()
                .for_each(|k| new_funded.push((k, per_unit)));
            notfunded.truncate(start);
            if !moves.is_empty() {
                to_fund.push((f.0, moves));
            }
        }
        // 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| {
            let mut tries = 0;
            // this set of transactions just initializes us for bookkeeping
            #[allow(clippy::clone_double_ref)] // sigh
            let mut to_fund_txs: Vec<_> = chunk
                .par_iter()
                .map(|(k, m)| {
                    (
                        k.clone(),
                        Transaction::new_unsigned_instructions(system_instruction::transfer_many(
                            &k.pubkey(),
                            &m,
                        )),
                    )
                })
                .collect();
            let amount = chunk[0].1[0].1;
            while !to_fund_txs.is_empty() {
                let receivers = to_fund_txs
                    .iter()
                    .fold(0, |len, (_, tx)| len + tx.message().instructions.len());
                println!(
                    "{} {} to {} in {} txs",
                    if tries == 0 {
                        "transferring"
                    } else {
                        " retrying"
                    },
                    amount,
                    receivers,
                    to_fund_txs.len(),
                );
                let (blockhash, _fee_calculator) = client.get_recent_blockhash().unwrap();
                // re-sign retained to_fund_txes with updated blockhash
                to_fund_txs.par_iter_mut().for_each(|(k, tx)| {
                    tx.sign(&[*k], blockhash);
                });
                to_fund_txs.iter().for_each(|(_, tx)| {
                    client.async_send_transaction(tx.clone()).expect("transfer");
                });
                // retry anything that seems to have dropped through cracks
                //  again since these txs are all or nothing, they're fine to
                //  retry
                for _ in 0..10 {
                    to_fund_txs.retain(|(_, tx)| !verify_funding_transfer(client, &tx, amount));
                    if to_fund_txs.is_empty() {
                        break;
                    }
                    sleep(Duration::from_millis(100));
                }
                tries += 1;
            }
            println!("transferred");
        });
        println!("funded: {} left: {}", new_funded.len(), notfunded.len());
        funded = new_funded;
    }
}
pub fn fund_keys < T : Client > ( client : & T , source : & Keypair , dests : & [ Keypair ] , difs : u64 ) { let total = difs * dests . len ( ) as u64 ; let mut funded : Vec < ( & Keypair , u64 ) > = vec ! [ ( source total ) ] ; let mut notfunded : Vec < & Keypair > = dests . iter ( ) . collect ( ) ; println ! ( " " dests len ( ) ) ; while ! notfunded . is_empty ( ) { let mut new_funded : Vec < ( & Keypair , u64 ) > = vec ! [ ] ; let mut to_fund = vec ! [ ] ; println ! ( " " funded len ( ) ) ; for f in & mut funded { let max_units = cmp :: min ( notfunded . len ( ) , MAX_SPENDS_PER_TX ) ; if max_units == 0 { break ; } let start = notfunded . len ( ) - max_units ; let per_unit = f . 1 / ( max_units as u64 ) ; let moves : Vec < _ > = notfunded [ start .. ] . iter ( ) . map ( | k | ( k . pubkey ( ) , per_unit ) ) . collect ( ) ; notfunded [ start .. ] . iter ( ) . for_each ( | k | new_funded . push ( ( k , per_unit ) ) ) ; notfunded . truncate ( start ) ; if ! moves . is_empty ( ) { to_fund . push ( ( f . 0 , moves ) ) ; } } // 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 | { let mut tries = 0 ; // this set of transactions just initializes us for bookkeeping # [ allow ( clippy clone_double_ref ) ] // sigh let mut to_fund_txs : Vec < _ > = chunk . par_iter ( ) . map ( | ( k , m ) | { ( k . clone ( ) , Transaction :: new_unsigned_instructions ( system_instruction :: transfer_many ( & k . pubkey ( ) , & m , ) ) , ) } ) . collect ( ) ; let amount = chunk [ 0 ] . 1 [ 0 ] . 1 ; while ! to_fund_txs . is_empty ( ) { let receivers = to_fund_txs . iter ( ) . fold ( 0 , | len , ( _ , tx ) | len + tx . message ( ) . instructions . len ( ) ) ; println ! ( " " if tries 0 { " " } else { " " } amount receivers to_fund_txs len ( ) ) ; let ( blockhash , _fee_calculator ) = client . get_recent_blockhash ( ) . unwrap ( ) ; // re-sign retained to_fund_txes with updated blockhash to_fund_txs . par_iter_mut ( ) . for_each ( | ( k , tx ) | { tx . sign ( & [ * k ] , blockhash ) ; } ) ; to_fund_txs . iter ( ) . for_each ( | ( _ , tx ) | { client . async_send_transaction ( tx . clone ( ) ) . expect ( " " ) ; } ) ; // retry anything that seems to have dropped through cracks //  again since these txs are all or nothing, they're fine to //  retry for _ in 0 .. 10 { to_fund_txs . retain ( | ( _ , tx ) | ! verify_funding_transfer ( client , & tx , amount ) ) ; if to_fund_txs . is_empty ( ) { break ; } sleep ( Duration :: from_millis ( 100 ) ) ; } tries += 1 ; } println ! ( " " ) ; } ) ; println ! ( " " new_funded len ( ) notfunded len ( ) ) ; funded = new_funded ; } }
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
&T
source
&Keypair
dests
&[Keypair]
difs
u64
client
&T
source
&Keypair
dests
&[Keypair]
difs
u64