1use serde::{Deserialize, Serialize};
2use tycho_types::models::*;
3use tycho_types::prelude::*;
4use tycho_util::serde_helpers;
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct GenTimings {
11 #[serde(with = "serde_helpers::string")]
12 pub gen_lt: u64,
13 pub gen_utime: u32,
14}
15
16impl GenTimings {
17 pub const fn max_by_lt(self, other: Self) -> Self {
18 if other.gen_lt > self.gen_lt {
19 other
20 } else {
21 self
22 }
23 }
24}
25
26#[derive(Debug, Clone, Copy, PartialEq, Eq)]
27pub struct LastTransactionId {
28 pub lt: u64,
29 pub hash: HashBytes,
30}
31
32impl Serialize for LastTransactionId {
33 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
34 where
35 S: serde::Serializer,
36 {
37 #[derive(Serialize)]
38 #[serde(rename_all = "camelCase")]
39 struct LastTransactionId<'a> {
40 is_exact: bool,
41 #[serde(with = "serde_helpers::string")]
42 lt: u64,
43 hash: &'a HashBytes,
44 }
45
46 LastTransactionId {
47 is_exact: true,
48 lt: self.lt,
49 hash: &self.hash,
50 }
51 .serialize(serializer)
52 }
53}
54
55#[derive(Default, Debug, Copy, Clone, Eq, PartialEq, Serialize, Deserialize)]
56#[serde(rename_all = "camelCase")]
57pub struct StateTimings {
58 pub last_mc_block_seqno: u32,
59 pub last_mc_utime: u32,
60 pub mc_time_diff: i64,
61 pub smallest_known_lt: Option<u64>,
62}
63
64pub fn serialize_account(account: &Account) -> Result<Cell, tycho_types::error::Error> {
65 let cx = Cell::empty_context();
66 let mut builder = CellBuilder::new();
67 account.address.store_into(&mut builder, cx)?;
68 account.storage_stat.store_into(&mut builder, cx)?;
69 account.last_trans_lt.store_into(&mut builder, cx)?;
70 account.balance.store_into(&mut builder, cx)?;
71 account.state.store_into(&mut builder, cx)?;
72 builder.build_ext(cx)
73}