stratus/eth/primitives/
pending_block.rs

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