Repository: unionlabs/union
File: light-clients/tendermint-light-client/src/client.rs (Rust)

Code before:

    fn verify_upgrade_and_update_state(
        _deps: DepsMut<Self::CustomQuery>,
        _upgrade_client_state: Self::ClientState,
        _upgrade_consensus_state: Self::ConsensusState,
        _proof_upgrade_client: Vec<u8>,
        _proof_upgrade_consensus_state: Vec<u8>,
    ) -> Result<(), Self::Error> {
        Err(Error::Unimplemented)
    }

    fn migrate_client_store(_deps: Deps<Self::CustomQuery>) -> Result<(), Self::Error> {
        Err(Error::Unimplemented)
    }

    fn status(
        deps: Deps<Self::CustomQuery>,
        env: &cosmwasm_std::Env,
    ) -> Result<Status, Self::Error> {
        let client_state: WasmClientState = read_client_state(deps)?;

        // TODO(aeryz): when refactoring the tm client, we should consider making this non-optional
        // because otherwise we always have to check if the inner height is zero.
        match client_state.data.frozen_height {
            Some(h) if h != ZERO_HEIGHT => return Ok(Status::Frozen),
            _ => {}
        }

        let Some(consensus_state) = read_consensus_state::<Self::CustomQuery, ConsensusState>(
            deps,
            &client_state.latest_height,
        )?
        else {
            return Ok(Status::Expired);
        };

        if is_client_expired(
            &consensus_state.data.timestamp,
            client_state.data.trusting_period,
            env.block
                .time
                .try_into()
                .map_err(|_| Error::InvalidHostTimestamp(env.block.time))?,
        ) {
            return Ok(Status::Expired);
        }

        Ok(Status::Active)
    }

    fn export_metadata(

Review comment (suggestion):
if `Height` implements `PartialEq` and `Eq`, you can just do `Some(FROZEN_HEIGHT)` as it's `const`.

ref: [StructuralEq](https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html)

Code after:

    fn verify_upgrade_and_update_state(
        _deps: DepsMut<Self::CustomQuery>,
        _upgrade_client_state: Self::ClientState,
        _upgrade_consensus_state: Self::ConsensusState,
        _proof_upgrade_client: Vec<u8>,
        _proof_upgrade_consensus_state: Vec<u8>,
    ) -> Result<(), Self::Error> {
        Err(Error::Unimplemented)
    }

    fn migrate_client_store(_deps: Deps<Self::CustomQuery>) -> Result<(), Self::Error> {
        Err(Error::Unimplemented)
    }

    fn status(
        deps: Deps<Self::CustomQuery>,
        env: &cosmwasm_std::Env,
    ) -> Result<Status, Self::Error> {
        let client_state: WasmClientState = read_client_state(deps)?;

        // TODO(aeryz): when refactoring the tm client, we should consider making this non-optional
        // because otherwise we always have to check if the inner height is zero.
        if client_state.data.frozen_height.unwrap_or(ZERO_HEIGHT) != ZERO_HEIGHT {
            return Ok(Status::Frozen);
        }

        let Some(consensus_state) = read_consensus_state::<Self::CustomQuery, ConsensusState>(
            deps,
            &client_state.latest_height,
        )?
        else {
            return Ok(Status::Expired);
        };

        if is_client_expired(
            &consensus_state.data.timestamp,
            client_state.data.trusting_period,
            env.block
                .time
                .try_into()
                .map_err(|_| Error::InvalidHostTimestamp(env.block.time))?,
        ) {
            return Ok(Status::Expired);
        }

        Ok(Status::Active)
    }

    fn export_metadata(
        _deps: Deps<Self::CustomQuery>,