light_client/rpc/
indexer.rs

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