stratus/eth/primitives/
pending_block.rs

1use display_json::DebugAsJson;
2use indexmap::IndexMap;
3
4use crate::eth::primitives::BlockNumber;
5use crate::eth::primitives::Hash;
6use crate::eth::primitives::PendingBlockHeader;
7use crate::eth::primitives::TransactionExecution;
8
9/// Block that is being mined and receiving updates.
10#[derive(DebugAsJson, Clone, Default, serde::Serialize)]
11pub struct PendingBlock {
12    pub header: PendingBlockHeader,
13    // TODO: review why we use an indexmap here but not everywhere else
14    pub transactions: IndexMap<Hash, TransactionExecution>,
15}
16
17impl PendingBlock {
18    /// Creates a new [`PendingBlock`] with the specified number.
19    pub fn new_at_now(number: BlockNumber) -> Self {
20        Self {
21            header: PendingBlockHeader::new_at_now(number),
22            transactions: IndexMap::new(),
23        }
24    }
25
26    /// Adds a transaction execution to the block.
27    pub fn push_transaction(&mut self, tx: TransactionExecution) {
28        self.transactions.insert(tx.info.hash, tx);
29    }
30}