1#![cfg(feature = "std")]
2
3use chrono::{DateTime, NaiveDateTime, Utc};
4use fuel_core_client::client::schema::block::{Block as ClientBlock, Header as ClientHeader};
5use fuel_tx::Bytes32;
6
7#[derive(Debug)]
8pub struct Header {
9 pub id: Bytes32,
10 pub da_height: u64,
11 pub transactions_count: u64,
12 pub message_receipt_count: u64,
13 pub transactions_root: Bytes32,
14 pub message_receipt_root: Bytes32,
15 pub height: u32,
16 pub prev_root: Bytes32,
17 pub time: Option<DateTime<Utc>>,
18 pub application_hash: Bytes32,
19}
20
21impl From<ClientHeader> for Header {
22 fn from(client_header: ClientHeader) -> Self {
23 let naive = NaiveDateTime::from_timestamp_opt(client_header.time.0.to_unix(), 0);
24 let time = naive.map(|time| DateTime::<Utc>::from_utc(time, Utc));
25
26 Self {
27 id: client_header.id.0 .0,
28 da_height: client_header.da_height.0,
29 transactions_count: client_header.transactions_count.0,
30 message_receipt_count: client_header.message_receipt_count.0,
31 transactions_root: client_header.transactions_root.0 .0,
32 message_receipt_root: client_header.message_receipt_root.0 .0,
33 height: client_header.height.0,
34 prev_root: client_header.prev_root.0 .0,
35 time,
36 application_hash: client_header.application_hash.0 .0,
37 }
38 }
39}
40
41#[derive(Debug)]
42pub struct Block {
43 pub id: Bytes32,
44 pub header: Header,
45 pub transactions: Vec<Bytes32>,
46}
47
48impl From<ClientBlock> for Block {
49 fn from(client_block: ClientBlock) -> Self {
50 let transactions = client_block
51 .transactions
52 .iter()
53 .map(|tx| tx.id.0 .0)
54 .collect();
55
56 Self {
57 id: client_block.id.0 .0,
58 header: client_block.header.into(),
59 transactions,
60 }
61 }
62}