light_client/rpc/
indexer.rs

1use async_trait::async_trait;
2use light_compressed_account::QueueType;
3use solana_pubkey::Pubkey;
4
5use super::LightClient;
6use crate::indexer::{
7    Address, AddressWithTree, BatchAddressUpdateIndexerResponse, CompressedAccount,
8    GetCompressedAccountsByOwnerConfig, GetCompressedTokenAccountsByOwnerOrDelegateOptions, Hash,
9    Indexer, IndexerError, IndexerRpcConfig, Items, ItemsWithCursor, MerkleProof,
10    MerkleProofWithContext, NewAddressProofWithContext, OwnerBalance, PaginatedOptions, Response,
11    RetryConfig, SignatureWithMetadata, TokenAccount, 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<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<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<TokenAccount>>, 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<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        queue_type: QueueType,
208        num_elements: u16,
209        start_offset: Option<u64>,
210        config: Option<IndexerRpcConfig>,
211    ) -> Result<Response<Items<MerkleProofWithContext>>, IndexerError> {
212        Ok(self
213            .indexer
214            .as_mut()
215            .ok_or(IndexerError::NotInitialized)?
216            .get_queue_elements(
217                merkle_tree_pubkey,
218                queue_type,
219                num_elements,
220                start_offset,
221                config,
222            )
223            .await?)
224    }
225
226    async fn get_subtrees(
227        &self,
228        merkle_tree_pubkey: [u8; 32],
229        config: Option<IndexerRpcConfig>,
230    ) -> Result<Response<Items<[u8; 32]>>, IndexerError> {
231        Ok(self
232            .indexer
233            .as_ref()
234            .ok_or(IndexerError::NotInitialized)?
235            .get_subtrees(merkle_tree_pubkey, config)
236            .await?)
237    }
238
239    async fn get_compressed_balance_by_owner(
240        &self,
241        owner: &Pubkey,
242        config: Option<IndexerRpcConfig>,
243    ) -> Result<Response<u64>, IndexerError> {
244        Ok(self
245            .indexer
246            .as_ref()
247            .ok_or(IndexerError::NotInitialized)?
248            .get_compressed_balance_by_owner(owner, config)
249            .await?)
250    }
251
252    async fn get_compressed_mint_token_holders(
253        &self,
254        mint: &Pubkey,
255        options: Option<PaginatedOptions>,
256        config: Option<IndexerRpcConfig>,
257    ) -> Result<Response<ItemsWithCursor<OwnerBalance>>, IndexerError> {
258        Ok(self
259            .indexer
260            .as_ref()
261            .ok_or(IndexerError::NotInitialized)?
262            .get_compressed_mint_token_holders(mint, options, config)
263            .await?)
264    }
265
266    async fn get_compressed_token_accounts_by_delegate(
267        &self,
268        delegate: &Pubkey,
269        options: Option<GetCompressedTokenAccountsByOwnerOrDelegateOptions>,
270        config: Option<IndexerRpcConfig>,
271    ) -> Result<Response<ItemsWithCursor<TokenAccount>>, IndexerError> {
272        Ok(self
273            .indexer
274            .as_ref()
275            .ok_or(IndexerError::NotInitialized)?
276            .get_compressed_token_accounts_by_delegate(delegate, options, config)
277            .await?)
278    }
279
280    async fn get_compression_signatures_for_address(
281        &self,
282        address: &[u8; 32],
283        options: Option<PaginatedOptions>,
284        config: Option<IndexerRpcConfig>,
285    ) -> Result<Response<ItemsWithCursor<SignatureWithMetadata>>, IndexerError> {
286        Ok(self
287            .indexer
288            .as_ref()
289            .ok_or(IndexerError::NotInitialized)?
290            .get_compression_signatures_for_address(address, options, config)
291            .await?)
292    }
293
294    async fn get_compression_signatures_for_owner(
295        &self,
296        owner: &Pubkey,
297        options: Option<PaginatedOptions>,
298        config: Option<IndexerRpcConfig>,
299    ) -> Result<Response<ItemsWithCursor<SignatureWithMetadata>>, IndexerError> {
300        Ok(self
301            .indexer
302            .as_ref()
303            .ok_or(IndexerError::NotInitialized)?
304            .get_compression_signatures_for_owner(owner, options, config)
305            .await?)
306    }
307
308    async fn get_compression_signatures_for_token_owner(
309        &self,
310        owner: &Pubkey,
311        options: Option<PaginatedOptions>,
312        config: Option<IndexerRpcConfig>,
313    ) -> Result<Response<ItemsWithCursor<SignatureWithMetadata>>, IndexerError> {
314        Ok(self
315            .indexer
316            .as_ref()
317            .ok_or(IndexerError::NotInitialized)?
318            .get_compression_signatures_for_token_owner(owner, options, config)
319            .await?)
320    }
321
322    async fn get_indexer_health(&self, config: Option<RetryConfig>) -> Result<bool, IndexerError> {
323        Ok(self
324            .indexer
325            .as_ref()
326            .ok_or(IndexerError::NotInitialized)?
327            .get_indexer_health(config)
328            .await?)
329    }
330}