Skip to main content

alloy_rpc_types_beacon/
proposer.rs

1//! Types for the proposer duties endpoint.
2//!
3//! See <https://ethereum.github.io/beacon-APIs/#/Validator/getProposerDuties>
4
5use crate::BlsPublicKey;
6use serde::{Deserialize, Serialize};
7use serde_with::{serde_as, DisplayFromStr};
8
9/// Response from the [`/eth/v1/validator/duties/proposer/{epoch}`](https://ethereum.github.io/beacon-APIs/#/Validator/getProposerDuties) endpoint.
10#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
11pub struct ProposerDutiesResponse {
12    /// Whether the response references an unverified execution payload.
13    #[serde(default)]
14    pub execution_optimistic: bool,
15    /// The dependent root for the response.
16    pub dependent_root: alloy_primitives::B256,
17    /// The list of proposer duties.
18    pub data: Vec<ProposerDuty>,
19}
20
21/// A single proposer duty entry.
22#[serde_as]
23#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
24pub struct ProposerDuty {
25    /// The BLS public key of the validator assigned to propose.
26    pub pubkey: BlsPublicKey,
27    /// The index of the validator in the validator registry.
28    #[serde_as(as = "DisplayFromStr")]
29    pub validator_index: u64,
30    /// The slot at which the validator is expected to propose.
31    #[serde_as(as = "DisplayFromStr")]
32    pub slot: u64,
33}
34
35#[cfg(test)]
36mod tests {
37    use super::*;
38
39    #[test]
40    fn serde_proposer_duties_response() {
41        let s = r#"{
42            "execution_optimistic": false,
43            "dependent_root": "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2",
44            "data": [
45                {
46                    "pubkey": "0x93247f2209abcacf57b75a51dafae777f9dd38bc7053d1af526f220a7489a6d3a2753e5f3e8b1cfe39b56f43611df74a",
47                    "validator_index": "1",
48                    "slot": "1"
49                }
50            ]
51        }"#;
52        let resp: ProposerDutiesResponse = serde_json::from_str(s).unwrap();
53        assert_eq!(resp.data.len(), 1);
54        assert_eq!(resp.data[0].validator_index, 1);
55        assert_eq!(resp.data[0].slot, 1);
56    }
57}