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, serde::Serialize, serde::Deserialize)]
10#[serde(rename_all = "camelCase")]
11pub struct SafeHeadResponse {
12    /// The L1 block.
13    pub l1_block: BlockNumHash,
14    /// The safe head.
15    pub safe_head: BlockNumHash,
16}
17
18#[cfg(test)]
19mod tests {
20    use super::*;
21
22    // <https://github.com/alloy-rs/op-alloy/issues/155>
23    #[test]
24    fn test_safe_head_response() {
25        let s = r#"{"l1Block":{"hash":"0x7de331305c2bb3e5642a2adcb9c003cc67cefc7b05a3da5a6a4b12cf3af15407","number":6834391},"safeHead":{"hash":"0xa5e5ec1ade7d6fef209f73861bf0080950cde74c4b0c07823983eb5225e282a8","number":18266679}}"#;
26        let _response: SafeHeadResponse = serde_json::from_str(s).unwrap();
27    }
28}