light_client/indexer/
options.rs

1use photon_api::models::{FilterSelector, Memcmp};
2use solana_account_decoder_client_types::UiDataSliceConfig;
3use solana_pubkey::Pubkey;
4
5#[derive(Debug, Clone)]
6pub struct GetCompressedTokenAccountsByOwnerOrDelegateOptions {
7    pub mint: Option<Pubkey>,
8    pub cursor: Option<String>,
9    pub limit: Option<u16>,
10}
11
12impl GetCompressedTokenAccountsByOwnerOrDelegateOptions {
13    pub fn new(mint: Option<Pubkey>) -> Self {
14        Self {
15            mint,
16            cursor: None,
17            limit: None,
18        }
19    }
20}
21
22/// **Cursor** is a unique identifier for a page of results by which the next page can be fetched.
23///
24/// **Limit** is the maximum number of results to return per page.
25pub struct PaginatedOptions {
26    pub cursor: Option<String>,
27    pub limit: Option<u16>,
28}
29
30pub struct GetCompressedAccountsByOwnerConfig {
31    pub filters: Option<Vec<GetCompressedAccountsFilter>>,
32    pub data_slice: Option<UiDataSliceConfig>,
33    pub cursor: Option<String>,
34    pub limit: Option<u16>,
35}
36
37#[derive(Clone)]
38pub struct GetCompressedAccountsFilter {
39    pub bytes: Vec<u8>,
40    pub offset: u32,
41}
42
43#[allow(clippy::from_over_into)]
44impl Into<FilterSelector> for GetCompressedAccountsFilter {
45    fn into(self) -> FilterSelector {
46        FilterSelector {
47            memcmp: Some(Box::new(Memcmp {
48                offset: self.offset,
49                bytes: base64::encode(&self.bytes), // TODO: double check
50            })),
51        }
52    }
53}
54
55impl GetCompressedAccountsByOwnerConfig {
56    pub fn filters_to_photon(&self) -> Option<Vec<FilterSelector>> {
57        self.filters
58            .as_ref()
59            .map(|filters| filters.iter().map(|f| f.clone().into()).collect())
60    }
61}
62
63/// Options for fetching queue elements (V2 with deduplicated nodes and address queue support).
64#[derive(Debug, Clone, Default)]
65pub struct QueueElementsV2Options {
66    pub output_queue_start_index: Option<u64>,
67    pub output_queue_limit: Option<u16>,
68    pub output_queue_zkp_batch_size: Option<u16>,
69    pub input_queue_start_index: Option<u64>,
70    pub input_queue_limit: Option<u16>,
71    pub input_queue_zkp_batch_size: Option<u16>,
72    pub address_queue_start_index: Option<u64>,
73    pub address_queue_limit: Option<u16>,
74    pub address_queue_zkp_batch_size: Option<u16>,
75}
76
77impl QueueElementsV2Options {
78    pub fn new() -> Self {
79        Self::default()
80    }
81
82    pub fn with_output_queue(mut self, start_index: Option<u64>, limit: Option<u16>) -> Self {
83        self.output_queue_start_index = start_index;
84        self.output_queue_limit = limit;
85        self
86    }
87
88    pub fn with_output_queue_batch_size(mut self, batch_size: Option<u16>) -> Self {
89        self.output_queue_zkp_batch_size = batch_size;
90        self
91    }
92
93    pub fn with_input_queue(mut self, start_index: Option<u64>, limit: Option<u16>) -> Self {
94        self.input_queue_start_index = start_index;
95        self.input_queue_limit = limit;
96        self
97    }
98
99    pub fn with_input_queue_batch_size(mut self, batch_size: Option<u16>) -> Self {
100        self.input_queue_zkp_batch_size = batch_size;
101        self
102    }
103
104    pub fn with_address_queue(mut self, start_index: Option<u64>, limit: Option<u16>) -> Self {
105        self.address_queue_start_index = start_index;
106        self.address_queue_limit = limit;
107        self
108    }
109
110    pub fn with_address_queue_batch_size(mut self, batch_size: Option<u16>) -> Self {
111        self.address_queue_zkp_batch_size = batch_size;
112        self
113    }
114}