kona_rpc/
response.rs

1//! Response to safe head request
2
3use alloy_eips::BlockNumHash;
4
5/// The safe head response.
6///
7/// <https://github.com/ethereum-optimism/optimism/blob/77c91d09eaa44d2c53bec60eb89c5c55737bc325/op-service/eth/output.go#L19-L22>
8/// Note: the optimism "eth.BlockID" type is number,hash <https://github.com/ethereum-optimism/optimism/blob/77c91d09eaa44d2c53bec60eb89c5c55737bc325/op-service/eth/id.go#L10-L13>
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
11#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
12pub struct SafeHeadResponse {
13    /// The L1 block.
14    pub l1_block: BlockNumHash,
15    /// The safe head.
16    pub safe_head: BlockNumHash,
17}
18
19#[cfg(test)]
20#[cfg(feature = "serde")]
21mod tests {
22    use super::*;
23
24    // <https://github.com/alloy-rs/op-alloy/issues/155>
25    #[test]
26    fn test_safe_head_response() {
27        let s = r#"{"l1Block":{"hash":"0x7de331305c2bb3e5642a2adcb9c003cc67cefc7b05a3da5a6a4b12cf3af15407","number":6834391},"safeHead":{"hash":"0xa5e5ec1ade7d6fef209f73861bf0080950cde74c4b0c07823983eb5225e282a8","number":18266679}}"#;
28        let _response: SafeHeadResponse = serde_json::from_str(s).unwrap();
29    }
30}