diff --git a/.changelog/unreleased/features/974-id-into-string.md b/.changelog/unreleased/features/974-id-into-string.md new file mode 100644 index 000000000..fb2d5bb3a --- /dev/null +++ b/.changelog/unreleased/features/974-id-into-string.md @@ -0,0 +1,2 @@ +- Provide `Into` for all identifiers types. + ([\#974](https://github.com/cosmos/ibc-rs/pull/974)) diff --git a/ibc-core/ics24-host/types/src/identifiers/chain_id.rs b/ibc-core/ics24-host/types/src/identifiers/chain_id.rs index 5b532aeef..a88fdc940 100644 --- a/ibc-core/ics24-host/types/src/identifiers/chain_id.rs +++ b/ibc-core/ics24-host/types/src/identifiers/chain_id.rs @@ -148,6 +148,12 @@ impl FromStr for ChainId { } } +impl From for String { + fn from(chain_id: ChainId) -> String { + chain_id.id + } +} + impl Display for ChainId { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> { write!(f, "{}", self.id) diff --git a/ibc-core/ics24-host/types/src/identifiers/channel_id.rs b/ibc-core/ics24-host/types/src/identifiers/channel_id.rs index f4dc7e2fa..3cfeacb7b 100644 --- a/ibc-core/ics24-host/types/src/identifiers/channel_id.rs +++ b/ibc-core/ics24-host/types/src/identifiers/channel_id.rs @@ -1,6 +1,7 @@ use core::fmt::{Debug, Display, Error as FmtError, Formatter}; use core::str::FromStr; +use derive_more::Into; use ibc_primitives::prelude::*; use crate::error::IdentifierError; @@ -22,7 +23,7 @@ const CHANNEL_ID_PREFIX: &str = "channel"; )] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] -#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Into)] pub struct ChannelId(String); impl ChannelId { diff --git a/ibc-core/ics24-host/types/src/identifiers/connection_id.rs b/ibc-core/ics24-host/types/src/identifiers/connection_id.rs index 10a2c8857..a0283f5f4 100644 --- a/ibc-core/ics24-host/types/src/identifiers/connection_id.rs +++ b/ibc-core/ics24-host/types/src/identifiers/connection_id.rs @@ -1,6 +1,7 @@ use core::fmt::{Display, Error as FmtError, Formatter}; use core::str::FromStr; +use derive_more::Into; use ibc_primitives::prelude::*; use crate::error::IdentifierError; @@ -22,7 +23,7 @@ const CONNECTION_ID_PREFIX: &str = "connection"; )] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] -#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Into)] pub struct ConnectionId(String); impl ConnectionId { diff --git a/ibc-core/ics24-host/types/src/identifiers/port_id.rs b/ibc-core/ics24-host/types/src/identifiers/port_id.rs index d1b640757..e1a0e062d 100644 --- a/ibc-core/ics24-host/types/src/identifiers/port_id.rs +++ b/ibc-core/ics24-host/types/src/identifiers/port_id.rs @@ -1,6 +1,7 @@ use core::fmt::{Display, Error as FmtError, Formatter}; use core::str::FromStr; +use derive_more::Into; use ibc_primitives::prelude::*; use crate::error::IdentifierError; @@ -22,7 +23,7 @@ const TRANSFER_PORT_ID: &str = "transfer"; )] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] -#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Into)] pub struct PortId(String); impl PortId { diff --git a/ibc-testkit/src/hosts/block.rs b/ibc-testkit/src/hosts/block.rs index be7419c65..9ce08cdce 100644 --- a/ibc-testkit/src/hosts/block.rs +++ b/ibc-testkit/src/hosts/block.rs @@ -148,7 +148,7 @@ impl HostBlock { let light_block = TestgenLightBlock::new_default_with_header( TestgenHeader::new(validators) .height(height) - .chain_id(&chain_id.to_string()) + .chain_id(chain_id.as_str()) .next_validators(next_validators) .time(timestamp.into_tm_time().expect("Never fails")), )