1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Serialize, Deserialize, PartialEq)]
4#[allow(missing_copy_implementations)]
5#[must_use]
7#[non_exhaustive]
8pub struct InherentData {
9 pub seed: u64,
11 pub timestamp: u64,
13}
14
15impl InherentData {
16 pub const fn new(seed: u64, timestamp: u64) -> Self {
18 Self { seed, timestamp }
19 }
20
21 #[cfg(all(feature = "rng", not(target_family = "wasm")))]
22 pub fn next(&self) -> Self {
23 Self {
24 seed: seeded_random::Random::from_seed(seeded_random::Seed::unsafe_new(self.seed)).gen(),
25 timestamp: std::time::SystemTime::now()
26 .duration_since(std::time::UNIX_EPOCH)
27 .unwrap()
28 .as_millis()
29 .try_into()
30 .unwrap(),
31 }
32 }
33
34 #[cfg(all(feature = "rng", feature = "std", not(target_family = "wasm")))]
39 pub fn unsafe_default() -> Self {
40 Self {
41 seed: seeded_random::Random::new().gen(),
42 timestamp: std::time::SystemTime::now()
43 .duration_since(std::time::UNIX_EPOCH)
44 .unwrap()
45 .as_millis()
46 .try_into()
47 .unwrap(),
48 }
49 }
50
51 pub const fn unsafe_clone(&self) -> Self {
56 Self {
57 seed: self.seed,
58 timestamp: self.timestamp,
59 }
60 }
61}
62
63#[cfg(test)]
64mod tests {}