bolt-cw-sdk 1.0.0

SDK for the BOLT protocol, providing utilities for interacting with the BOLT contracts.
Documentation
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug)]
pub struct Timestamp {
    /// The number of seconds since the Unix epoch (1970-01-01T00:00:00Z)
    pub seconds: u64,
    /// The number of nanoseconds since the last second
    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);
    }
}