diff --git a/packages/storage-plus/src/keys.rs b/packages/storage-plus/src/keys.rs index 9bb5a8742..4c4f2a515 100644 --- a/packages/storage-plus/src/keys.rs +++ b/packages/storage-plus/src/keys.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::Addr; +use cosmwasm_std::{Addr, Timestamp}; use std::marker::PhantomData; use crate::helpers::namespaces_with_key; @@ -250,7 +250,8 @@ impl From for IntKey { impl From> for IntKey { fn from(wrap: Vec) -> Self { - // TODO: assert proper length + // TODO: Consider properly handling case, when `wrap` has length not conforming for the + // wrapped integer type. IntKey { wrapped: wrap, data: PhantomData, @@ -264,6 +265,42 @@ impl From> for Vec { } } +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct TimestampKey(U64Key); + +impl TimestampKey { + pub fn new(ts: Timestamp) -> Self { + Self(ts.nanos().into()) + } +} + +impl<'a> PrimaryKey<'a> for TimestampKey { + type Prefix = (); + type SubPrefix = (); + + fn key(&self) -> Vec<&[u8]> { + self.0.key() + } +} + +impl<'a> Prefixer<'a> for TimestampKey { + fn prefix(&self) -> Vec<&[u8]> { + self.0.key() + } +} + +impl From> for TimestampKey { + fn from(val: Vec) -> Self { + Self(val.into()) + } +} + +impl From for TimestampKey { + fn from(val: Timestamp) -> Self { + Self::new(val) + } +} + #[cfg(test)] mod test { use super::*;