pangea_client/core/requests/
blocks.rs

1use std::collections::HashSet;
2
3use serde::{Deserialize, Serialize};
4
5use crate::{
6    core::types::{default_chains, ChainId},
7    query::Bound,
8    utils::serialize_comma_separated,
9};
10
11#[derive(Clone, Deserialize, Serialize, Debug)]
12#[allow(non_snake_case)]
13pub struct GetBlocksRequest {
14    #[serde(default = "default_chains")]
15    #[serde(
16        serialize_with = "serialize_comma_separated",
17        skip_serializing_if = "HashSet::is_empty"
18    )]
19    pub chains: HashSet<ChainId>,
20
21    // Inclusive lower bound if is Some for block number
22    #[serde(default)]
23    pub from_block: Bound,
24    // Exclusive upper bound if is Some for block number
25    #[serde(default)]
26    pub to_block: Bound,
27
28    // Inclusive lower bound if is Some for block timestamp
29    #[serde(default)]
30    pub from_timestamp: Option<i64>,
31    // Exclusive upper bound if is Some for block timestamp
32    #[serde(default)]
33    pub to_timestamp: Option<i64>,
34}
35
36impl Default for GetBlocksRequest {
37    fn default() -> Self {
38        Self {
39            chains: default_chains(),
40            from_block: Bound::default(),
41            to_block: Bound::default(),
42            from_timestamp: None,
43            to_timestamp: None,
44        }
45    }
46}