use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)]
pub struct Timestamp {
pub seconds: u64,
pub nanos: u64,
}
impl Timestamp {
pub fn new(seconds: u64, nanos: u64) -> Self {
Timestamp { seconds, nanos }
}
}
impl From<Timestamp> for cosmwasm_std::Timestamp {
fn from(ts: Timestamp) -> Self {
cosmwasm_std::Timestamp::from_seconds(ts.seconds).plus_nanos(ts.nanos)
}
}
impl From<cosmrs::tendermint::Time> for Timestamp {
fn from(ts: cosmrs::tendermint::Time) -> Self {
Timestamp {
seconds: ts.unix_timestamp() as u64,
nanos: 0,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_tendermint_conversion() {
let tm_time = cosmrs::tendermint::Time::from_unix_timestamp(1753112894, 0)
.expect("Failed to create tendermint time");
let ts: Timestamp = tm_time.into();
assert_eq!(ts.seconds, 1753112894);
assert_eq!(ts.nanos, 0);
}
}