loom_types_blockchain/
accountnoncetx.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
use alloy_primitives::TxHash;

#[derive(Debug, Clone, Default)]
pub struct AccountNonceAndTransactions {
    pub nonce: Option<u64>,
    pub txs: Vec<TxHash>,
}

impl AccountNonceAndTransactions {
    pub fn new() -> Self {
        Self::default()
    }

    pub fn add_tx_hash(&mut self, tx_hash: TxHash) -> &mut Self {
        self.txs.push(tx_hash);
        self
    }

    pub fn set_nonce(&mut self, nonce: Option<u64>) -> &mut Self {
        if let Some(cur_nonce) = self.nonce {
            if let Some(some_nonce) = nonce {
                if cur_nonce < some_nonce {
                    self.nonce = Some(some_nonce);
                }
                return self;
            }
        }
        self.nonce = nonce;
        self
    }
}