tempo_alloy/rpc/
pagination.rs

1use serde::{Deserialize, Serialize};
2
3/// Field sorting parameters.
4#[derive(Clone, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
5#[serde(rename_all = "camelCase")]
6pub struct Sort {
7    /// A field the items are compared with.
8    pub on: String,
9
10    /// An ordering direction.
11    pub order: SortOrder,
12}
13
14/// A sort order.
15#[derive(Clone, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
16#[serde(rename_all = "camelCase")]
17pub enum SortOrder {
18    Asc,
19    #[default]
20    Desc,
21}
22
23#[derive(Clone, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
24#[serde(rename_all = "camelCase")]
25pub struct PaginationParams<Filters> {
26    /// Cursor for pagination.
27    ///
28    /// The cursor format depends on the endpoint:
29    /// - `dex_getOrders`: Order ID (u128 encoded as string)
30    /// - `dex_getOrderbooks`: Book Key (B256 encoded as hex string)
31    ///
32    /// Defaults to first entry based on the sort and filter configuration.
33    /// Use the `nextCursor` in response to get the next set of results.
34    #[serde(skip_serializing_if = "Option::is_none")]
35    pub cursor: Option<String>,
36
37    /// Determines which items should be yielded in the response.
38    #[serde(skip_serializing_if = "Option::is_none")]
39    pub filters: Option<Filters>,
40
41    /// Maximum number of orders to return.
42    ///
43    /// Defaults to 10.
44    /// Maximum is 100.
45    #[serde(skip_serializing_if = "Option::is_none")]
46    pub limit: Option<usize>,
47
48    /// Determines the order of the items yielded in the response.
49    #[serde(skip_serializing_if = "Option::is_none")]
50    pub sort: Option<Sort>,
51}
52
53#[derive(Clone, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
54#[serde(rename_all = "camelCase")]
55pub struct FilterRange<T> {
56    pub min: Option<T>,
57    pub max: Option<T>,
58}
59
60impl<T: PartialOrd> FilterRange<T> {
61    /// Checks if a value is within this range (inclusive)
62    pub fn in_range(&self, value: T) -> bool {
63        if self.min.as_ref().is_some_and(|min| &value < min) {
64            return false;
65        }
66
67        if self.max.as_ref().is_some_and(|max| &value > max) {
68            return false;
69        }
70
71        true
72    }
73}