async fn initial_transfer(&mut self) -> Result<(), failure::Error> {
        log::info!(
            "Starting initial transfer. {} ETH will be send to each of {} new accounts",
            format_ether(&self.transfer_size),
            self.n_accounts
        );

        let mut signed_transfers = Vec::with_capacity(self.n_accounts);

        for to_idx in 0..self.n_accounts {
            let from_acc = &self.main_account.zk_acc;
            let to_acc = &self.accounts[to_idx];

            // Transfer size is (transfer_amount) + (fee for every tx to be sent) + (fee for final transfer
            // back to the main account).
            let transfer_amount = self.transfer_size.clone()
                + self.estimated_fee_for_op.clone() * (self.cycles_amount + 1);

            // Make amount packable.
            let packable_transfer_amount = closest_packable_fee_amount(&transfer_amount);

            // Fee for the transfer itself differs from the estimated fee.
            let fee = self.transfer_fee(&to_acc).await;
            let transfer = self.sign_transfer(from_acc, to_acc, packable_transfer_amount, fee);

            signed_transfers.push(transfer);
        }

        log::info!("Signed all the initial transfer transactions, sending");

        // Send txs by batches that can fit in one block.
        let to_verify = signed_transfers.len();
        let mut verified = 0;
        let txs_chunks = DynamicChunks::new(signed_transfers, &self.block_sizes);
        for tx_batch in txs_chunks {
            let mut sent_txs = SentTransactions::new();
            // Send each tx.
            // This has to be done synchronously, since we're sending from the same account
            // and truly async sending will result in a nonce mismatch errors.
            for (tx, eth_sign) in tx_batch {
                let tx_hash = self
                    .rpc_client
                    .send_tx(tx.clone(), eth_sign.clone())
                    .await?;
                sent_txs.add_tx_hash(tx_hash);
            }

            let sent_txs_amount = sent_txs.len();
            verified += sent_txs_amount;

            // Wait until all the transactions are verified.
            wait_for_verify(sent_txs, self.verify_timeout, &self.rpc_client).await?;

            log::info!(
                "Sent and verified {}/{} txs ({} on this iteration)",
                verified,
                to_verify,
                sent_txs_amount
            );
        }

        log::info!("All the initial transfers are completed");
        log::info!("Updating the accounts info and changing their public keys");

        // After all the initial transfer completed, we have to update new account IDs
        // and change public keys of accounts (so we'll be able to send transfers from them).
        let mut tx_futures = vec![];
        for account in self.accounts.iter() {
            let resp = self
                .rpc_client
                .account_state_info(account.address)
                .await
                .expect("rpc error");
            assert!(resp.id.is_some(), "Account ID is none for new account");
            account.set_account_id(resp.id);

            let change_pubkey_tx = FranklinTx::ChangePubKey(Box::new(
                account.create_change_pubkey_tx(None, true, false),
            ));

            let tx_future = self.rpc_client.send_tx(change_pubkey_tx, None);

            tx_futures.push(tx_future);
        }
        let mut sent_txs = SentTransactions::new();
        sent_txs.tx_hashes = try_join_all(tx_futures).await?;

        // Calculate the estimated amount of blocks for all the txs to be processed.
        let max_block_size = *self.block_sizes.iter().max().unwrap();
        let n_blocks = (self.accounts.len() / max_block_size + 1) as u32;
        wait_for_verify(sent_txs, self.verify_timeout * n_blocks, &self.rpc_client).await?;

        log::info!("All the accounts are prepared");

        log::info!("Initial transfers are sent and verified");

        Ok(())
    }
/// Splits the money from the main account between the intermediate accounts
/// with the `TransferToNew` operations.
Splits the money from the main account between the intermediate accounts
with the `TransferToNew` operations.
Splits the money from the main account between the intermediate accounts with the ` TransferToNew ` operations .
async fn initial_transfer(&mut self) -> Result<(), failure::Error> {
        log::info!(
            "Starting initial transfer. {} ETH will be send to each of {} new accounts",
            format_ether(&self.transfer_size),
            self.n_accounts
        );
        let mut signed_transfers = Vec::with_capacity(self.n_accounts);
        for to_idx in 0..self.n_accounts {
            let from_acc = &self.main_account.zk_acc;
            let to_acc = &self.accounts[to_idx];
            // Transfer size is (transfer_amount) + (fee for every tx to be sent) + (fee for final transfer
            // back to the main account).
            let transfer_amount = self.transfer_size.clone()
                + self.estimated_fee_for_op.clone() * (self.cycles_amount + 1);
            // Make amount packable.
            let packable_transfer_amount = closest_packable_fee_amount(&transfer_amount);
            // Fee for the transfer itself differs from the estimated fee.
            let fee = self.transfer_fee(&to_acc).await;
            let transfer = self.sign_transfer(from_acc, to_acc, packable_transfer_amount, fee);
            signed_transfers.push(transfer);
        }
        log::info!("Signed all the initial transfer transactions, sending");
        // Send txs by batches that can fit in one block.
        let to_verify = signed_transfers.len();
        let mut verified = 0;
        let txs_chunks = DynamicChunks::new(signed_transfers, &self.block_sizes);
        for tx_batch in txs_chunks {
            let mut sent_txs = SentTransactions::new();
            // Send each tx.
            // This has to be done synchronously, since we're sending from the same account
            // and truly async sending will result in a nonce mismatch errors.
            for (tx, eth_sign) in tx_batch {
                let tx_hash = self
                    .rpc_client
                    .send_tx(tx.clone(), eth_sign.clone())
                    .await?;
                sent_txs.add_tx_hash(tx_hash);
            }
            let sent_txs_amount = sent_txs.len();
            verified += sent_txs_amount;
            // Wait until all the transactions are verified.
            wait_for_verify(sent_txs, self.verify_timeout, &self.rpc_client).await?;
            log::info!(
                "Sent and verified {}/{} txs ({} on this iteration)",
                verified,
                to_verify,
                sent_txs_amount
            );
        }
        log::info!("All the initial transfers are completed");
        log::info!("Updating the accounts info and changing their public keys");
        // After all the initial transfer completed, we have to update new account IDs
        // and change public keys of accounts (so we'll be able to send transfers from them).
        let mut tx_futures = vec![];
        for account in self.accounts.iter() {
            let resp = self
                .rpc_client
                .account_state_info(account.address)
                .await
                .expect("rpc error");
            assert!(resp.id.is_some(), "Account ID is none for new account");
            account.set_account_id(resp.id);
            let change_pubkey_tx = FranklinTx::ChangePubKey(Box::new(
                account.create_change_pubkey_tx(None, true, false),
            ));
            let tx_future = self.rpc_client.send_tx(change_pubkey_tx, None);
            tx_futures.push(tx_future);
        }
        let mut sent_txs = SentTransactions::new();
        sent_txs.tx_hashes = try_join_all(tx_futures).await?;
        // Calculate the estimated amount of blocks for all the txs to be processed.
        let max_block_size = *self.block_sizes.iter().max().unwrap();
        let n_blocks = (self.accounts.len() / max_block_size + 1) as u32;
        wait_for_verify(sent_txs, self.verify_timeout * n_blocks, &self.rpc_client).await?;
        log::info!("All the accounts are prepared");
        log::info!("Initial transfers are sent and verified");
        Ok(())
    }
async fn initial_transfer ( & mut self ) -> Result < ( ) , failure :: Error > { log :: info ! ( " " format_ether ( self transfer_size ) self n_accounts ) ; let mut signed_transfers = Vec :: with_capacity ( self . n_accounts ) ; for to_idx in 0 .. self . n_accounts { let from_acc = & self . main_account . zk_acc ; let to_acc = & self . accounts [ to_idx ] ; // Transfer size is (transfer_amount) + (fee for every tx to be sent) + (fee for final transfer // back to the main account). let transfer_amount = self . transfer_size . clone ( ) + self . estimated_fee_for_op . clone ( ) * ( self . cycles_amount + 1 ) ; // Make amount packable. let packable_transfer_amount = closest_packable_fee_amount ( & transfer_amount ) ; // Fee for the transfer itself differs from the estimated fee. let fee = self . transfer_fee ( & to_acc ) . await ; let transfer = self . sign_transfer ( from_acc , to_acc , packable_transfer_amount , fee ) ; signed_transfers . push ( transfer ) ; } log :: info ! ( " " ) ; // Send txs by batches that can fit in one block. let to_verify = signed_transfers . len ( ) ; let mut verified = 0 ; let txs_chunks = DynamicChunks :: new ( signed_transfers , & self . block_sizes ) ; for tx_batch in txs_chunks { let mut sent_txs = SentTransactions :: new ( ) ; // Send each tx. // This has to be done synchronously, since we're sending from the same account // and truly async sending will result in a nonce mismatch errors. for ( tx , eth_sign ) in tx_batch { let tx_hash = self . rpc_client . send_tx ( tx . clone ( ) , eth_sign . clone ( ) ) . await ? ; sent_txs . add_tx_hash ( tx_hash ) ; } let sent_txs_amount = sent_txs . len ( ) ; verified += sent_txs_amount ; // Wait until all the transactions are verified. wait_for_verify ( sent_txs , self . verify_timeout , & self . rpc_client ) . await ? ; log :: info ! ( " " verified to_verify sent_txs_amount ) ; } log :: info ! ( " " ) ; log :: info ! ( " " ) ; // After all the initial transfer completed, we have to update new account IDs // and change public keys of accounts (so we'll be able to send transfers from them). let mut tx_futures = vec ! [ ] ; for account in self . accounts . iter ( ) { let resp = self . rpc_client . account_state_info ( account . address ) . await . expect ( " " ) ; assert ! ( resp id is_some ( ) " " ) ; account . set_account_id ( resp . id ) ; let change_pubkey_tx = FranklinTx :: ChangePubKey ( Box :: new ( account . create_change_pubkey_tx ( None , true , false ) , ) ) ; let tx_future = self . rpc_client . send_tx ( change_pubkey_tx , None ) ; tx_futures . push ( tx_future ) ; } let mut sent_txs = SentTransactions :: new ( ) ; sent_txs . tx_hashes = try_join_all ( tx_futures ) . await ? ; // Calculate the estimated amount of blocks for all the txs to be processed. let max_block_size = * self . block_sizes . iter ( ) . max ( ) . unwrap ( ) ; let n_blocks = ( self . accounts . len ( ) / max_block_size + 1 ) as u32 ; wait_for_verify ( sent_txs , self . verify_timeout * n_blocks , & self . rpc_client ) . await ? ; log :: info ! ( " " ) ; log :: info ! ( " " ) ; Ok ( ( ) ) }
Splits the money from the main account between the intermediate accounts
with the `TransferToNew` operations.
Splits the money from the main account between the intermediate accounts with the ` TransferToNew ` operations .
&mut self