Skip to main content

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, GetCompressedAccountsByOwnerConfig,
7    GetCompressedTokenAccountsByOwnerOrDelegateOptions, Hash, Indexer, IndexerError,
8    IndexerRpcConfig, Items, ItemsWithCursor, MerkleProof, NewAddressProofWithContext,
9    OwnerBalance, PaginatedOptions, QueueElementsResult, QueueElementsV2Options, QueueInfoResult,
10    QueueLeafIndex, Response, RetryConfig, SignatureWithMetadata, TokenBalance,
11    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_balance(
93        &self,
94        address: Option<Address>,
95        hash: Option<Hash>,
96        config: Option<IndexerRpcConfig>,
97    ) -> Result<Response<u64>, IndexerError> {
98        Ok(self
99            .indexer
100            .as_ref()
101            .ok_or(IndexerError::NotInitialized)?
102            .get_compressed_balance(address, hash, config)
103            .await?)
104    }
105
106    async fn get_compressed_token_account_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_token_account_balance(address, hash, config)
117            .await?)
118    }
119
120    async fn get_multiple_compressed_accounts(
121        &self,
122        addresses: Option<Vec<Address>>,
123        hashes: Option<Vec<Hash>>,
124        config: Option<IndexerRpcConfig>,
125    ) -> Result<Response<Items<Option<CompressedAccount>>>, IndexerError> {
126        Ok(self
127            .indexer
128            .as_ref()
129            .ok_or(IndexerError::NotInitialized)?
130            .get_multiple_compressed_accounts(addresses, hashes, config)
131            .await?)
132    }
133
134    async fn get_compressed_token_balances_by_owner_v2(
135        &self,
136        owner: &Pubkey,
137        options: Option<GetCompressedTokenAccountsByOwnerOrDelegateOptions>,
138        config: Option<IndexerRpcConfig>,
139    ) -> Result<Response<ItemsWithCursor<TokenBalance>>, IndexerError> {
140        Ok(self
141            .indexer
142            .as_ref()
143            .ok_or(IndexerError::NotInitialized)?
144            .get_compressed_token_balances_by_owner_v2(owner, options, config)
145            .await?)
146    }
147
148    async fn get_compression_signatures_for_account(
149        &self,
150        hash: Hash,
151        config: Option<IndexerRpcConfig>,
152    ) -> Result<Response<Items<SignatureWithMetadata>>, IndexerError> {
153        Ok(self
154            .indexer
155            .as_ref()
156            .ok_or(IndexerError::NotInitialized)?
157            .get_compression_signatures_for_account(hash, config)
158            .await?)
159    }
160
161    async fn get_multiple_new_address_proofs(
162        &self,
163        merkle_tree_pubkey: [u8; 32],
164        addresses: Vec<[u8; 32]>,
165        config: Option<IndexerRpcConfig>,
166    ) -> Result<Response<Items<NewAddressProofWithContext>>, IndexerError> {
167        Ok(self
168            .indexer
169            .as_ref()
170            .ok_or(IndexerError::NotInitialized)?
171            .get_multiple_new_address_proofs(merkle_tree_pubkey, addresses, config)
172            .await?)
173    }
174
175    async fn get_queue_elements(
176        &mut self,
177        merkle_tree_pubkey: [u8; 32],
178        options: QueueElementsV2Options,
179        config: Option<IndexerRpcConfig>,
180    ) -> Result<Response<QueueElementsResult>, IndexerError> {
181        Ok(self
182            .indexer
183            .as_mut()
184            .ok_or(IndexerError::NotInitialized)?
185            .get_queue_elements(merkle_tree_pubkey, options, config)
186            .await?)
187    }
188
189    async fn get_queue_leaf_indices(
190        &self,
191        merkle_tree_pubkey: [u8; 32],
192        limit: u16,
193        start_index: Option<u64>,
194        config: Option<IndexerRpcConfig>,
195    ) -> Result<Response<Items<QueueLeafIndex>>, IndexerError> {
196        Ok(self
197            .indexer
198            .as_ref()
199            .ok_or(IndexerError::NotInitialized)?
200            .get_queue_leaf_indices(merkle_tree_pubkey, limit, start_index, config)
201            .await?)
202    }
203
204    async fn get_queue_info(
205        &self,
206        config: Option<IndexerRpcConfig>,
207    ) -> Result<Response<QueueInfoResult>, IndexerError> {
208        Ok(self
209            .indexer
210            .as_ref()
211            .ok_or(IndexerError::NotInitialized)?
212            .get_queue_info(config)
213            .await?)
214    }
215
216    async fn get_subtrees(
217        &self,
218        merkle_tree_pubkey: [u8; 32],
219        config: Option<IndexerRpcConfig>,
220    ) -> Result<Response<Items<[u8; 32]>>, IndexerError> {
221        Ok(self
222            .indexer
223            .as_ref()
224            .ok_or(IndexerError::NotInitialized)?
225            .get_subtrees(merkle_tree_pubkey, config)
226            .await?)
227    }
228
229    async fn get_compressed_balance_by_owner(
230        &self,
231        owner: &Pubkey,
232        config: Option<IndexerRpcConfig>,
233    ) -> Result<Response<u64>, IndexerError> {
234        Ok(self
235            .indexer
236            .as_ref()
237            .ok_or(IndexerError::NotInitialized)?
238            .get_compressed_balance_by_owner(owner, config)
239            .await?)
240    }
241
242    async fn get_compressed_mint_token_holders(
243        &self,
244        mint: &Pubkey,
245        options: Option<PaginatedOptions>,
246        config: Option<IndexerRpcConfig>,
247    ) -> Result<Response<ItemsWithCursor<OwnerBalance>>, IndexerError> {
248        Ok(self
249            .indexer
250            .as_ref()
251            .ok_or(IndexerError::NotInitialized)?
252            .get_compressed_mint_token_holders(mint, options, config)
253            .await?)
254    }
255
256    async fn get_compression_signatures_for_address(
257        &self,
258        address: &[u8; 32],
259        options: Option<PaginatedOptions>,
260        config: Option<IndexerRpcConfig>,
261    ) -> Result<Response<ItemsWithCursor<SignatureWithMetadata>>, IndexerError> {
262        Ok(self
263            .indexer
264            .as_ref()
265            .ok_or(IndexerError::NotInitialized)?
266            .get_compression_signatures_for_address(address, options, config)
267            .await?)
268    }
269
270    async fn get_compression_signatures_for_owner(
271        &self,
272        owner: &Pubkey,
273        options: Option<PaginatedOptions>,
274        config: Option<IndexerRpcConfig>,
275    ) -> Result<Response<ItemsWithCursor<SignatureWithMetadata>>, IndexerError> {
276        Ok(self
277            .indexer
278            .as_ref()
279            .ok_or(IndexerError::NotInitialized)?
280            .get_compression_signatures_for_owner(owner, options, config)
281            .await?)
282    }
283
284    async fn get_compression_signatures_for_token_owner(
285        &self,
286        owner: &Pubkey,
287        options: Option<PaginatedOptions>,
288        config: Option<IndexerRpcConfig>,
289    ) -> Result<Response<ItemsWithCursor<SignatureWithMetadata>>, IndexerError> {
290        Ok(self
291            .indexer
292            .as_ref()
293            .ok_or(IndexerError::NotInitialized)?
294            .get_compression_signatures_for_token_owner(owner, options, config)
295            .await?)
296    }
297
298    async fn get_indexer_health(&self, config: Option<RetryConfig>) -> Result<bool, IndexerError> {
299        Ok(self
300            .indexer
301            .as_ref()
302            .ok_or(IndexerError::NotInitialized)?
303            .get_indexer_health(config)
304            .await?)
305    }
306}