hermes_relayer_components/chain/impls/forward/queries/
client_state.rs

1use cgp::core::error::CanRaiseError;
2use cgp::core::inner::HasInner;
3
4use crate::chain::traits::queries::client_state::{
5    CanQueryClientState, CanQueryClientStateWithProofs, ClientStateQuerier,
6    ClientStateWithProofsQuerier,
7};
8use crate::chain::traits::types::client_state::HasClientStateType;
9use crate::chain::traits::types::ibc::HasIbcChainTypes;
10use crate::chain::traits::types::proof::HasCommitmentProofType;
11
12pub struct ForwardQueryClientState;
13
14impl<Chain, InChain, Counterparty, ClientState> ClientStateQuerier<Chain, Counterparty>
15    for ForwardQueryClientState
16where
17    Chain:
18        HasInner<Inner = InChain> + CanRaiseError<InChain::Error> + HasIbcChainTypes<Counterparty>,
19    InChain: CanQueryClientState<Counterparty, ClientId = Chain::ClientId, Height = Chain::Height>,
20    Counterparty: HasClientStateType<Chain, ClientState = ClientState>
21        + HasClientStateType<InChain, ClientState = ClientState>,
22{
23    async fn query_client_state(
24        chain: &Chain,
25        client_id: &Chain::ClientId,
26        height: &Chain::Height,
27    ) -> Result<ClientState, Chain::Error> {
28        let client_state = chain
29            .inner()
30            .query_client_state(client_id, height)
31            .await
32            .map_err(Chain::raise_error)?;
33
34        Ok(client_state)
35    }
36}
37
38impl<Chain, InChain, Counterparty, ClientState, CommitmentProof>
39    ClientStateWithProofsQuerier<Chain, Counterparty> for ForwardQueryClientState
40where
41    Chain: HasInner<Inner = InChain>
42        + CanRaiseError<InChain::Error>
43        + HasIbcChainTypes<Counterparty>
44        + HasCommitmentProofType<CommitmentProof = CommitmentProof>,
45    InChain: CanQueryClientStateWithProofs<
46        Counterparty,
47        ClientId = Chain::ClientId,
48        Height = Chain::Height,
49        CommitmentProof = CommitmentProof,
50    >,
51    Counterparty: HasClientStateType<Chain, ClientState = ClientState>
52        + HasClientStateType<InChain, ClientState = ClientState>,
53{
54    async fn query_client_state_with_proofs(
55        chain: &Chain,
56        client_id: &Chain::ClientId,
57        height: &Chain::Height,
58    ) -> Result<(ClientState, CommitmentProof), Chain::Error> {
59        let result = chain
60            .inner()
61            .query_client_state_with_proofs(client_id, height)
62            .await
63            .map_err(Chain::raise_error)?;
64
65        Ok(result)
66    }
67}