Skip to content

Commit

Permalink
imp: derive Hash on Timestamp instead of explicit implementation (#1011)
Browse files Browse the repository at this point in the history
  • Loading branch information
Farhad-Shabani authored Dec 18, 2023
1 parent 38f746d commit d2a91ea
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- `[ibc-primitives]` Derive `Hash` on `Timestamp` instead of explicit
implementation ([#1011](https://github.com/cosmos/ibc-rs/pull/1005))
14 changes: 2 additions & 12 deletions ibc-primitives/src/types/timestamp.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Defines the representation of timestamps used in IBC.

use core::fmt::{Display, Error as FmtError, Formatter};
use core::hash::{Hash, Hasher};
use core::hash::Hash;
use core::num::ParseIntError;
use core::ops::{Add, Sub};
use core::str::FromStr;
Expand All @@ -24,7 +24,7 @@ pub const ZERO_DURATION: Duration = Duration::from_secs(0);
/// of timestamp.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(PartialEq, Eq, Copy, Clone, Debug, Default, PartialOrd, Ord)]
#[derive(PartialEq, Eq, Copy, Clone, Debug, Default, PartialOrd, Ord, Hash)]
pub struct Timestamp {
// Note: The schema representation is the timestamp in nanoseconds (as we do with borsh).
#[cfg_attr(feature = "schema", schemars(with = "u64"))]
Expand Down Expand Up @@ -85,16 +85,6 @@ impl scale_info::TypeInfo for Timestamp {
}
}

// TODO: derive when tendermint::Time supports it:
// https://github.com/informalsystems/tendermint-rs/pull/1054
#[allow(clippy::derived_hash_with_manual_eq)]
impl Hash for Timestamp {
fn hash<H: Hasher>(&self, state: &mut H) {
let odt: Option<OffsetDateTime> = self.time.map(Into::into);
odt.hash(state);
}
}

/// The expiry result when comparing two timestamps.
/// - If either timestamp is invalid (0), the result is `InvalidTimestamp`.
/// - If the left timestamp is strictly after the right timestamp, the result is `Expired`.
Expand Down

0 comments on commit d2a91ea

Please sign in to comment.