-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Abstract components to query connection end (#167)
* Abstract connection end query * Formatting * Improve error handling in connection end query CLI --------- Co-authored-by: Romain Ruetschi <[email protected]> Co-authored-by: Soares Chen <[email protected]>
- Loading branch information
1 parent
248fa3e
commit 7b3720c
Showing
10 changed files
with
117 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
crates/cosmos/cosmos-client-components/src/impls/queries/connection_end.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use cgp_core::HasErrorType; | ||
use hermes_relayer_components::chain::traits::queries::connection_end::ConnectionEndQuerier; | ||
use hermes_relayer_components::chain::traits::types::connection::HasConnectionEndType; | ||
use hermes_relayer_components::chain::traits::types::ibc::HasIbcChainTypes; | ||
use ibc_relayer::chain::handle::ChainHandle; | ||
use ibc_relayer::chain::requests::IncludeProof; | ||
use ibc_relayer::chain::requests::QueryConnectionRequest; | ||
use ibc_relayer::chain::requests::QueryHeight; | ||
use ibc_relayer_types::core::ics03_connection::connection::ConnectionEnd; | ||
use ibc_relayer_types::core::ics24_host::identifier::ConnectionId; | ||
use ibc_relayer_types::Height; | ||
|
||
use crate::traits::chain_handle::HasBlockingChainHandle; | ||
|
||
pub struct QueryCosmosConnectionEndFromChainHandle; | ||
|
||
impl<Chain, Counterparty> ConnectionEndQuerier<Chain, Counterparty> | ||
for QueryCosmosConnectionEndFromChainHandle | ||
where | ||
Chain: HasConnectionEndType<Counterparty, ConnectionEnd = ConnectionEnd> | ||
+ HasIbcChainTypes<Counterparty, Height = Height, ConnectionId = ConnectionId> | ||
+ HasBlockingChainHandle | ||
+ HasErrorType, | ||
{ | ||
async fn query_connection_end( | ||
chain: &Chain, | ||
connection_id: &Chain::ConnectionId, | ||
height: Option<&Chain::Height>, | ||
) -> Result<Chain::ConnectionEnd, Chain::Error> { | ||
let connection_id = connection_id.clone(); | ||
let height = height.cloned(); | ||
chain | ||
.with_blocking_chain_handle(move |chain_handle| { | ||
let query_height = if let Some(height) = height { | ||
QueryHeight::Specific(height) | ||
} else { | ||
QueryHeight::Latest | ||
}; | ||
let (connection_end, _) = chain_handle | ||
.query_connection( | ||
QueryConnectionRequest { | ||
connection_id: connection_id.clone(), | ||
height: query_height, | ||
}, | ||
IncludeProof::No, | ||
) | ||
.map_err(Chain::raise_error)?; | ||
|
||
Ok(connection_end) | ||
}) | ||
.await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
crates/relayer/relayer-components/src/chain/traits/queries/connection_end.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use cgp_core::prelude::*; | ||
|
||
use crate::chain::traits::types::connection::HasConnectionEndType; | ||
use crate::chain::traits::types::ibc::HasIbcChainTypes; | ||
|
||
#[derive_component(ConnectionEndQuerierComponent, ConnectionEndQuerier<Chain>)] | ||
#[async_trait] | ||
pub trait CanQueryConnectionEnd<Counterparty>: | ||
HasConnectionEndType<Counterparty> + HasIbcChainTypes<Counterparty> + HasErrorType | ||
{ | ||
async fn query_connection_end( | ||
&self, | ||
connection_id: &Self::ConnectionId, | ||
height: Option<&Self::Height>, | ||
) -> Result<Self::ConnectionEnd, Self::Error>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters