light_client/rpc/
indexer.rs

1use async_trait::async_trait;
2use solana_pubkey::Pubkey;
3
4use super::LightClient;
5use crate::indexer::{
6    Address, AddressWithTree, BatchAddressUpdateIndexerResponse, CompressedAccount,
7    CompressedTokenAccount, GetCompressedAccountsByOwnerConfig,
8    GetCompressedTokenAccountsByOwnerOrDelegateOptions, Hash, Indexer, IndexerError,
9    IndexerRpcConfig, Items, ItemsWithCursor, MerkleProof, NewAddressProofWithContext,
10    OwnerBalance, PaginatedOptions, QueueElementsResult, QueueInfoResult, Response, RetryConfig,
11    SignatureWithMetadata, TokenBalance, ValidityProofWithContext,
12};
13
14#[async_trait]
15impl Indexer for LightClient {
16    async fn get_validity_proof(
17        &self,
18        hashes: Vec<Hash>,
19        new_addresses_with_trees: Vec<AddressWithTree>,
20        config: Option<IndexerRpcConfig>,
21    ) -> Result<Response<ValidityProofWithContext>, IndexerError> {
22        Ok(self
23            .indexer
24            .as_ref()
25            .ok_or(IndexerError::NotInitialized)?
26            .get_validity_proof(hashes, new_addresses_with_trees, config)
27            .await?)
28    }
29
30    async fn get_indexer_slot(&self, config: Option<RetryConfig>) -> Result<u64, IndexerError> {
31        Ok(self
32            .indexer
33            .as_ref()
34            .ok_or(IndexerError::NotInitialized)?
35            .get_indexer_slot(config)
36            .await?)
37    }
38
39    async fn get_multiple_compressed_account_proofs(
40        &self,
41        hashes: Vec<[u8; 32]>,
42        config: Option<IndexerRpcConfig>,
43    ) -> Result<Response<Items<MerkleProof>>, IndexerError> {
44        Ok(self
45            .indexer
46            .as_ref()
47            .ok_or(IndexerError::NotInitialized)?
48            .get_multiple_compressed_account_proofs(hashes, config)
49            .await?)
50    }
51
52    async fn get_compressed_accounts_by_owner(
53        &self,
54        owner: &Pubkey,
55        options: Option<GetCompressedAccountsByOwnerConfig>,
56        config: Option<IndexerRpcConfig>,
57    ) -> Result<Response<ItemsWithCursor<CompressedAccount>>, IndexerError> {
58        Ok(self
59            .indexer
60            .as_ref()
61            .ok_or(IndexerError::NotInitialized)?
62            .get_compressed_accounts_by_owner(owner, options, config)
63            .await?)
64    }
65
66    async fn get_compressed_account(
67        &self,
68        address: Address,
69        config: Option<IndexerRpcConfig>,
70    ) -> Result<Response<Option<CompressedAccount>>, IndexerError> {
71        Ok(self
72            .indexer
73            .as_ref()
74            .ok_or(IndexerError::NotInitialized)?
75            .get_compressed_account(address, config)
76            .await?)
77    }
78
79    async fn get_compressed_account_by_hash(
80        &self,
81        hash: Hash,
82        config: Option<IndexerRpcConfig>,
83    ) -> Result<Response<Option<CompressedAccount>>, IndexerError> {
84        Ok(self
85            .indexer
86            .as_ref()
87            .ok_or(IndexerError::NotInitialized)?
88            .get_compressed_account_by_hash(hash, config)
89            .await?)
90    }
91
92    async fn get_compressed_token_accounts_by_owner(
93        &self,
94        owner: &Pubkey,
95        options: Option<GetCompressedTokenAccountsByOwnerOrDelegateOptions>,
96        config: Option<IndexerRpcConfig>,
97    ) -> Result<Response<ItemsWithCursor<CompressedTokenAccount>>, IndexerError> {
98        Ok(self
99            .indexer
100            .as_ref()
101            .ok_or(IndexerError::NotInitialized)?
102            .get_compressed_token_accounts_by_owner(owner, options, config)
103            .await?)
104    }
105
106    async fn get_compressed_balance(
107        &self,
108        address: Option<Address>,
109        hash: Option<Hash>,
110        config: Option<IndexerRpcConfig>,
111    ) -> Result<Response<u64>, IndexerError> {
112        Ok(self
113            .indexer
114            .as_ref()
115            .ok_or(IndexerError::NotInitialized)?
116            .get_compressed_balance(address, hash, config)
117            .await?)
118    }
119
120    async fn get_compressed_token_account_balance(
121        &self,
122        address: Option<Address>,
123        hash: Option<Hash>,
124        config: Option<IndexerRpcConfig>,
125    ) -> Result<Response<u64>, IndexerError> {
126        Ok(self
127            .indexer
128            .as_ref()
129            .ok_or(IndexerError::NotInitialized)?
130            .get_compressed_token_account_balance(address, hash, config)
131            .await?)
132    }
133
134    async fn get_multiple_compressed_accounts(
135        &self,
136        addresses: Option<Vec<Address>>,
137        hashes: Option<Vec<Hash>>,
138        config: Option<IndexerRpcConfig>,
139    ) -> Result<Response<Items<Option<CompressedAccount>>>, IndexerError> {
140        Ok(self
141            .indexer
142            .as_ref()
143            .ok_or(IndexerError::NotInitialized)?
144            .get_multiple_compressed_accounts(addresses, hashes, config)
145            .await?)
146    }
147
148    async fn get_compressed_token_balances_by_owner_v2(
149        &self,
150        owner: &Pubkey,
151        options: Option<GetCompressedTokenAccountsByOwnerOrDelegateOptions>,
152        config: Option<IndexerRpcConfig>,
153    ) -> Result<Response<ItemsWithCursor<TokenBalance>>, IndexerError> {
154        Ok(self
155            .indexer
156            .as_ref()
157            .ok_or(IndexerError::NotInitialized)?
158            .get_compressed_token_balances_by_owner_v2(owner, options, config)
159            .await?)
160    }
161
162    async fn get_compression_signatures_for_account(
163        &self,
164        hash: Hash,
165        config: Option<IndexerRpcConfig>,
166    ) -> Result<Response<Items<SignatureWithMetadata>>, IndexerError> {
167        Ok(self
168            .indexer
169            .as_ref()
170            .ok_or(IndexerError::NotInitialized)?
171            .get_compression_signatures_for_account(hash, config)
172            .await?)
173    }
174
175    async fn get_multiple_new_address_proofs(
176        &self,
177        merkle_tree_pubkey: [u8; 32],
178        addresses: Vec<[u8; 32]>,
179        config: Option<IndexerRpcConfig>,
180    ) -> Result<Response<Items<NewAddressProofWithContext>>, IndexerError> {
181        Ok(self
182            .indexer
183            .as_ref()
184            .ok_or(IndexerError::NotInitialized)?
185            .get_multiple_new_address_proofs(merkle_tree_pubkey, addresses, config)
186            .await?)
187    }
188
189    async fn get_address_queue_with_proofs(
190        &mut self,
191        merkle_tree_pubkey: &Pubkey,
192        zkp_batch_size: u16,
193        start_offset: Option<u64>,
194        config: Option<IndexerRpcConfig>,
195    ) -> Result<Response<BatchAddressUpdateIndexerResponse>, IndexerError> {
196        Ok(self
197            .indexer
198            .as_mut()
199            .ok_or(IndexerError::NotInitialized)?
200            .get_address_queue_with_proofs(merkle_tree_pubkey, zkp_batch_size, start_offset, config)
201            .await?)
202    }
203
204    async fn get_queue_elements(
205        &mut self,
206        merkle_tree_pubkey: [u8; 32],
207        output_queue_start_index: Option<u64>,
208        output_queue_limit: Option<u16>,
209        input_queue_start_index: Option<u64>,
210        input_queue_limit: Option<u16>,
211        config: Option<IndexerRpcConfig>,
212    ) -> Result<Response<QueueElementsResult>, IndexerError> {
213        Ok(self
214            .indexer
215            .as_mut()
216            .ok_or(IndexerError::NotInitialized)?
217            .get_queue_elements(
218                merkle_tree_pubkey,
219                output_queue_start_index,
220                output_queue_limit,
221                input_queue_start_index,
222                input_queue_limit,
223                config,
224            )
225            .await?)
226    }
227
228    async fn get_queue_info(
229        &self,
230        config: Option<IndexerRpcConfig>,
231    ) -> Result<Response<QueueInfoResult>, IndexerError> {
232        Ok(self
233            .indexer
234            .as_ref()
235            .ok_or(IndexerError::NotInitialized)?
236            .get_queue_info(config)
237            .await?)
238    }
239
240    async fn get_queue_elements_v2(
241        &mut self,
242        merkle_tree_pubkey: [u8; 32],
243        options: crate::indexer::QueueElementsV2Options,
244        config: Option<IndexerRpcConfig>,
245    ) -> Result<Response<crate::indexer::QueueElementsV2Result>, IndexerError> {
246        Ok(self
247            .indexer
248            .as_mut()
249            .ok_or(IndexerError::NotInitialized)?
250            .get_queue_elements_v2(merkle_tree_pubkey, options, config)
251            .await?)
252    }
253    async fn get_subtrees(
254        &self,
255        merkle_tree_pubkey: [u8; 32],
256        config: Option<IndexerRpcConfig>,
257    ) -> Result<Response<Items<[u8; 32]>>, IndexerError> {
258        Ok(self
259            .indexer
260            .as_ref()
261            .ok_or(IndexerError::NotInitialized)?
262            .get_subtrees(merkle_tree_pubkey, config)
263            .await?)
264    }
265
266    async fn get_compressed_balance_by_owner(
267        &self,
268        owner: &Pubkey,
269        config: Option<IndexerRpcConfig>,
270    ) -> Result<Response<u64>, IndexerError> {
271        Ok(self
272            .indexer
273            .as_ref()
274            .ok_or(IndexerError::NotInitialized)?
275            .get_compressed_balance_by_owner(owner, config)
276            .await?)
277    }
278
279    async fn get_compressed_mint_token_holders(
280        &self,
281        mint: &Pubkey,
282        options: Option<PaginatedOptions>,
283        config: Option<IndexerRpcConfig>,
284    ) -> Result<Response<ItemsWithCursor<OwnerBalance>>, IndexerError> {
285        Ok(self
286            .indexer
287            .as_ref()
288            .ok_or(IndexerError::NotInitialized)?
289            .get_compressed_mint_token_holders(mint, options, config)
290            .await?)
291    }
292
293    async fn get_compressed_token_accounts_by_delegate(
294        &self,
295        delegate: &Pubkey,
296        options: Option<GetCompressedTokenAccountsByOwnerOrDelegateOptions>,
297        config: Option<IndexerRpcConfig>,
298    ) -> Result<Response<ItemsWithCursor<CompressedTokenAccount>>, IndexerError> {
299        Ok(self
300            .indexer
301            .as_ref()
302            .ok_or(IndexerError::NotInitialized)?
303            .get_compressed_token_accounts_by_delegate(delegate, options, config)
304            .await?)
305    }
306
307    async fn get_compression_signatures_for_address(
308        &self,
309        address: &[u8; 32],
310        options: Option<PaginatedOptions>,
311        config: Option<IndexerRpcConfig>,
312    ) -> Result<Response<ItemsWithCursor<SignatureWithMetadata>>, IndexerError> {
313        Ok(self
314            .indexer
315            .as_ref()
316            .ok_or(IndexerError::NotInitialized)?
317            .get_compression_signatures_for_address(address, options, config)
318            .await?)
319    }
320
321    async fn get_compression_signatures_for_owner(
322        &self,
323        owner: &Pubkey,
324        options: Option<PaginatedOptions>,
325        config: Option<IndexerRpcConfig>,
326    ) -> Result<Response<ItemsWithCursor<SignatureWithMetadata>>, IndexerError> {
327        Ok(self
328            .indexer
329            .as_ref()
330            .ok_or(IndexerError::NotInitialized)?
331            .get_compression_signatures_for_owner(owner, options, config)
332            .await?)
333    }
334
335    async fn get_compression_signatures_for_token_owner(
336        &self,
337        owner: &Pubkey,
338        options: Option<PaginatedOptions>,
339        config: Option<IndexerRpcConfig>,
340    ) -> Result<Response<ItemsWithCursor<SignatureWithMetadata>>, IndexerError> {
341        Ok(self
342            .indexer
343            .as_ref()
344            .ok_or(IndexerError::NotInitialized)?
345            .get_compression_signatures_for_token_owner(owner, options, config)
346            .await?)
347    }
348
349    async fn get_indexer_health(&self, config: Option<RetryConfig>) -> Result<bool, IndexerError> {
350        Ok(self
351            .indexer
352            .as_ref()
353            .ok_or(IndexerError::NotInitialized)?
354            .get_indexer_health(config)
355            .await?)
356    }
357}