Skip to content

Commit

Permalink
Change serialize for channel state
Browse files Browse the repository at this point in the history
  • Loading branch information
ljoss17 committed Dec 12, 2023
1 parent 20b9f27 commit 2b4a2d9
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions crates/relayer-types/src/core/ics04_channel/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ pub enum UpgradeState {
/// explicitly, this is an attempt to capture the lifecycle of a
/// channel, beginning from the `Uninitialized` state, through the
/// `Open` state, before finally being `Closed`.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Deserialize)]
pub enum State {
/// Default state
Uninitialized,
Expand All @@ -444,6 +444,23 @@ pub enum State {
Flushcomplete,
}

impl Serialize for State {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
match self {
Self::Uninitialized => serializer.serialize_str("Uninitialized"),
Self::Init => serializer.serialize_str("Init"),
Self::TryOpen => serializer.serialize_str("TryOpen"),
Self::Open(_) => serializer.serialize_str("Open"),
Self::Closed => serializer.serialize_str("Closed"),
Self::Flushing => serializer.serialize_str("Flushing"),
Self::Flushcomplete => serializer.serialize_str("Flushcomplete"),
}
}
}

impl State {
/// Yields the state as a string
pub fn as_string(&self) -> &'static str {
Expand Down Expand Up @@ -522,10 +539,7 @@ impl State {
/// Provides a `to_string` method.
impl Display for State {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> {
match self {
Self::Open(_) => write!(f, "Open"),
_ => write!(f, "{}", self.as_string()),
}
write!(f, "{}", self.as_string())
}
}

Expand Down

0 comments on commit 2b4a2d9

Please sign in to comment.