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