kona_rpc/
attributes.rs

1//! Optimism Payload attributes that reference the parent L2 block.
2
3use kona_protocol::L2BlockInfo;
4use op_alloy_rpc_types_engine::OpPayloadAttributes;
5
6/// Optimism Payload Attributes with parent block reference.
7#[derive(Debug, Clone, PartialEq)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9pub struct OpAttributesWithParent {
10    /// The payload attributes.
11    pub attributes: OpPayloadAttributes,
12    /// The parent block reference.
13    pub parent: L2BlockInfo,
14    /// Whether the current batch is the last in its span.
15    pub is_last_in_span: bool,
16}
17
18impl OpAttributesWithParent {
19    /// Create a new [OpAttributesWithParent] instance.
20    pub const fn new(
21        attributes: OpPayloadAttributes,
22        parent: L2BlockInfo,
23        is_last_in_span: bool,
24    ) -> Self {
25        Self { attributes, parent, is_last_in_span }
26    }
27
28    /// Returns the payload attributes.
29    pub const fn attributes(&self) -> &OpPayloadAttributes {
30        &self.attributes
31    }
32
33    /// Returns the parent block reference.
34    pub const fn parent(&self) -> &L2BlockInfo {
35        &self.parent
36    }
37
38    /// Returns whether the current batch is the last in its span.
39    pub const fn is_last_in_span(&self) -> bool {
40        self.is_last_in_span
41    }
42}
43
44#[cfg(test)]
45mod tests {
46    use super::*;
47
48    #[test]
49    fn test_op_attributes_with_parent() {
50        let attributes = OpPayloadAttributes::default();
51        let parent = L2BlockInfo::default();
52        let is_last_in_span = true;
53        let op_attributes_with_parent =
54            OpAttributesWithParent::new(attributes.clone(), parent, is_last_in_span);
55
56        assert_eq!(op_attributes_with_parent.attributes(), &attributes);
57        assert_eq!(op_attributes_with_parent.parent(), &parent);
58        assert_eq!(op_attributes_with_parent.is_last_in_span(), is_last_in_span);
59    }
60}