-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
imp(ics-07): simplify
ClientType
impl in cw contract (#1202)
* impl TryFrom * simplify Tendermint ClientType impl * add comment * rm Clone bound * Implement From<ConsensusState> * Remove unneeded dependency * Format cargo.toml file * nit * update gh workflow titles --------- Signed-off-by: Rano | Ranadeep <[email protected]> Co-authored-by: Sean Chen <[email protected]>
- Loading branch information
1 parent
534a465
commit 4ea4dcb
Showing
8 changed files
with
25 additions
and
68 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
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: 1 addition & 52 deletions
53
ibc-clients/ics07-tendermint/cw-contract/src/client_type.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 |
---|---|---|
@@ -1,63 +1,12 @@ | ||
use ibc_client_cw::api::ClientType; | ||
use ibc_client_tendermint::client_state::ClientState; | ||
use ibc_client_tendermint::consensus_state::ConsensusState; | ||
use ibc_client_tendermint::types::{ | ||
ConsensusState as ConsensusStateType, TENDERMINT_CONSENSUS_STATE_TYPE_URL, | ||
}; | ||
use ibc_core::client::types::error::ClientError; | ||
use ibc_core::derive::ConsensusState as ConsensusStateDerive; | ||
use ibc_core::primitives::proto::Any; | ||
|
||
/// A unit struct that represents the Tendermint client type. | ||
#[derive(Clone, Debug)] | ||
pub struct TendermintClient; | ||
|
||
impl<'a> ClientType<'a> for TendermintClient { | ||
type ClientState = ClientState; | ||
type ConsensusState = AnyConsensusState; | ||
} | ||
|
||
#[derive(Clone, Debug, ConsensusStateDerive)] | ||
pub enum AnyConsensusState { | ||
Tendermint(ConsensusState), | ||
} | ||
|
||
impl From<ConsensusStateType> for AnyConsensusState { | ||
fn from(value: ConsensusStateType) -> Self { | ||
AnyConsensusState::Tendermint(value.into()) | ||
} | ||
} | ||
|
||
impl TryFrom<AnyConsensusState> for ConsensusStateType { | ||
type Error = ClientError; | ||
|
||
fn try_from(value: AnyConsensusState) -> Result<Self, Self::Error> { | ||
match value { | ||
AnyConsensusState::Tendermint(state) => Ok(state.into_inner()), | ||
} | ||
} | ||
} | ||
|
||
impl From<AnyConsensusState> for Any { | ||
fn from(value: AnyConsensusState) -> Self { | ||
match value { | ||
AnyConsensusState::Tendermint(cs) => cs.into(), | ||
} | ||
} | ||
} | ||
|
||
impl TryFrom<Any> for AnyConsensusState { | ||
type Error = ClientError; | ||
|
||
fn try_from(raw: Any) -> Result<Self, Self::Error> { | ||
match raw.type_url.as_str() { | ||
TENDERMINT_CONSENSUS_STATE_TYPE_URL => { | ||
let cs = ConsensusState::try_from(raw)?; | ||
Ok(AnyConsensusState::Tendermint(cs)) | ||
} | ||
_ => Err(ClientError::UnknownConsensusStateType { | ||
consensus_state_type: raw.type_url, | ||
}), | ||
} | ||
} | ||
type ConsensusState = ConsensusState; | ||
} |
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