Repository: aptos-labs/aptos-core
File: crates/aptos-faucet/core/src/funder/mint.rs (Rust)

Code before:
    pub async fn update_asset_account(
        &self,
        asset_name: &str,
        new_account: LocalAccount,
    ) -> Result<()> {
        let account_rwlock = self
            .get_asset_account(asset_name)
            .map_err(|e| anyhow::anyhow!("{}", e))?;
        *account_rwlock.write().await = new_account;
        Ok(())
    }

    /// Core processing logic that handles transaction submission.
    pub async fn process(
        &self,
        client: &Client,
        amount: u64,
        receiver_address: AccountAddress,
        check_only: bool,
        wait_for_transactions: bool,
        asset_name: &str,
    ) -> Result<Vec<SignedTransaction>, AptosTapError> {
        // Check if the receiver account already exists.
        let receiver_exists = client.get_account(receiver_address).await.is_ok();

        if receiver_exists && amount == 0 {
            return Err(AptosTapError::new(
                format!(
                    "Account {} already exists and amount asked for is 0",
                    receiver_address
                ),
                AptosTapErrorCode::InvalidRequest,
            ));
        }

        if check_only {
            return Ok(vec![]);
        }

        let asset_config = self.get_asset_config(asset_name)?;
        let transaction_factory = self.get_transaction_factory().await?;

        let txn = {
            // Orderless transactions don't increment the sequence number, so a
            // read lock is sufficient.
            let faucet_account = self.get_asset_account(asset_name)?.read().await;

            let payload = match &asset_config.transaction_method {
                TransactionMethod::EntryFunction(entry_function_id) => {
                    // Create ModuleId from module_address and module_name
                    let module_id = ModuleId::new(

Review comment (suggestion):
We can be smarter here, only fetch `receiver_exists` if amount is zero, we don't care about it otherwise.

Code after:
    pub async fn update_asset_account(
        &self,
        asset_name: &str,
        new_account: LocalAccount,
    ) -> Result<()> {
        let account_rwlock = self
            .get_asset_account(asset_name)
            .map_err(|e| anyhow::anyhow!("{}", e))?;
        *account_rwlock.write().await = new_account;
        Ok(())
    }

    /// Core processing logic that handles transaction submission.
    pub async fn process(
        &self,
        client: &Client,
        amount: u64,
        receiver_address: AccountAddress,
        check_only: bool,
        wait_for_transactions: bool,
        asset_name: &str,
    ) -> Result<Vec<SignedTransaction>, AptosTapError> {
        if amount == 0 {
            let receiver_exists = client.get_account(receiver_address).await.is_ok();
            if receiver_exists {
                return Err(AptosTapError::new(
                    format!(
                        "Account {} already exists and amount asked for is 0",
                        receiver_address
                    ),
                    AptosTapErrorCode::InvalidRequest,
                ));
            }
        }

        if check_only {
            return Ok(vec![]);
        }

        let asset_config = self.get_asset_config(asset_name)?;
        let transaction_factory = self.get_transaction_factory().await?;

        let txn = {
            // Orderless transactions don't increment the sequence number, so a
            // read lock is sufficient.
            let faucet_account = self.get_asset_account(asset_name)?.read().await;

            let payload = match &asset_config.transaction_method {
                TransactionMethod::EntryFunction(entry_function_id) => {
                    // Create ModuleId from module_address and module_name
                    let module_id = ModuleId::new(