loom_types_events/
node.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use alloy_primitives::TxHash;
use alloy_rpc_types::{Block, Header, Log};

use loom_types_blockchain::{GethStateUpdateVec, MempoolTx};

use crate::Message;

#[derive(Clone, Debug)]
pub struct NodeMempoolDataUpdate {
    pub tx_hash: TxHash,
    pub mempool_tx: MempoolTx,
}

pub type MessageMempoolDataUpdate = Message<NodeMempoolDataUpdate>;

#[derive(Clone, Debug)]
pub struct BlockStateUpdate {
    pub block_header: Header,
    pub state_update: GethStateUpdateVec,
}

#[derive(Clone, Debug)]
pub struct BlockLogs {
    pub block_header: Header,
    pub logs: Vec<Log>,
}

#[derive(Clone, Debug, Default)]
pub struct BlockHeader {
    pub header: Header,
    pub next_block_number: u64,
    pub next_block_timestamp: u64,
}

pub type MessageBlockHeader = Message<BlockHeader>;
pub type MessageBlock = Message<Block>;
pub type MessageBlockLogs = Message<BlockLogs>;
pub type MessageBlockStateUpdate = Message<BlockStateUpdate>;

impl BlockHeader {
    pub fn new(header: Header) -> Self {
        let next_block_number = header.number + 1;
        let next_block_timestamp = header.timestamp + 12;
        Self { header, next_block_number, next_block_timestamp }
    }
}