Repository: aptos-labs/aptos-core
File: crates/aptos/src/move_tool/mod.rs (Rust)

Code before:
                )
                .await;

            match staging_area_response {
                Ok(response) => match response.into_inner() {
                    Some(_) => Ok(false), // StagingArea is not empty
                    None => Ok(true),     // TODO: determine which case this is
                },
                Err(RestError::Api(aptos_error_response))
                    if aptos_error_response.error.error_code
                        == AptosErrorCode::ResourceNotFound =>
                {
                    Ok(true) // The resource doesn't exist
                },
                Err(rest_err) => Err(CliError::from(rest_err)),
            }
        },
        Some(session_path) => {
            let sess = Session::load(session_path)?;

            let (_, account_address) = txn_options.get_public_key_and_address()?;

            let staging_area_bytes = sess
                .state_store()
                .get_resource_bytes(
                    &StateKey::resource(&account_address, &StructTag {
                        address: large_packages_module_address,
                        module: Identifier::new("large_packages").unwrap(),
                        name: Identifier::new("StagingArea").unwrap(),
                        type_args: vec![],
                    })
                    .unwrap(),
                    None,
                )
                .map_err(|e| {
                    CliError::UnexpectedError(format!("Failed to get staging area: {}", e))
                })?;

            Ok(staging_area_bytes.is_none())
        },
    }
}

/// Cleans up the `StagingArea` resource under an account, which is used for chunked publish operations
#[derive(Parser)]
pub struct ClearStagingArea {
    #[clap(flatten)]
    pub(crate) txn_options: TransactionOptions,

    #[clap(flatten)]
    pub(crate) large_packages_module: LargePackagesModuleOption,

Review comment (suggestion):
nit: I think you can use `FromStr` for tag, so re-use `format!("{}::large_packages::StagingArea", large_packages_module_address)` from above case.

Code after:
        None => {
            let client = txn_options.rest_client()?;

            let staging_area_response = client
                .get_account_resource(account_address, &staging_area_type_name)
                .await;

            match staging_area_response {
                Ok(response) => match response.into_inner() {
                    Some(_) => Ok(false), // StagingArea is not empty
                    None => Ok(true),     // TODO: determine which case this is
                },
                Err(RestError::Api(aptos_error_response))
                    if aptos_error_response.error.error_code
                        == AptosErrorCode::ResourceNotFound =>
                {
                    Ok(true) // The resource doesn't exist
                },
                Err(rest_err) => Err(CliError::from(rest_err)),
            }
        },
        Some(session_path) => {
            let sess = Session::load(session_path)?;

            let staging_area_bytes = sess
                .state_store()
                .get_resource_bytes(
                    &StateKey::resource(
                        &account_address,
                        &StructTag::from_str(&staging_area_type_name)
                            .expect("Should be able to construct staging area tag"),
                    )
                    .expect("Should be able to construct staging area state key"),
                    None,
                )
                .map_err(|e| {
                    CliError::UnexpectedError(format!("Failed to get staging area: {}", e))
                })?;

            Ok(staging_area_bytes.is_none())
        },
    }
}

/// Cleans up the `StagingArea` resource under an account, which is used for chunked publish operations
#[derive(Parser)]
pub struct ClearStagingArea {
    #[clap(flatten)]
    pub(crate) txn_options: TransactionOptions,

    #[clap(flatten)]