loom_types_blockchain/
mempool_tx.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
use alloy_primitives::{BlockNumber, TxHash};
use alloy_rpc_types::{Log, Transaction};
use chrono::{DateTime, Utc};

use crate::{FetchState, GethStateUpdate};

#[derive(Clone, Debug)]
pub struct MempoolTx {
    pub source: String,
    pub tx_hash: TxHash,
    pub time: DateTime<Utc>,
    pub tx: Option<Transaction>,
    pub logs: Option<Vec<Log>>,
    pub mined: Option<BlockNumber>,
    pub failed: Option<bool>,
    pub state_update: Option<GethStateUpdate>,
    pub pre_state: Option<FetchState<GethStateUpdate>>,
}

impl MempoolTx {
    pub fn new() -> MempoolTx {
        MempoolTx { ..MempoolTx::default() }
    }
    pub fn new_with_hash(tx_hash: TxHash) -> MempoolTx {
        MempoolTx { tx_hash, ..MempoolTx::default() }
    }
}

impl Default for MempoolTx {
    fn default() -> Self {
        MempoolTx {
            source: "unknown".to_string(),
            tx_hash: TxHash::repeat_byte(0),
            time: Utc::now(),
            tx: None,
            state_update: None,
            logs: None,
            mined: None,
            failed: None,
            pre_state: None,
        }
    }
}