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, OwnerBalance,
9 PaginatedOptions, QueueElementsResult, QueueElementsV2Options, QueueInfoResult, QueueLeafIndex,
10 Response, RetryConfig, SignatureWithMetadata, TokenBalance, ValidityProofWithContext,
11};
12
13#[async_trait]
14impl Indexer for LightClient {
15 async fn get_validity_proof(
16 &self,
17 hashes: Vec<Hash>,
18 new_addresses_with_trees: Vec<AddressWithTree>,
19 config: Option<IndexerRpcConfig>,
20 ) -> Result<Response<ValidityProofWithContext>, IndexerError> {
21 Ok(self
22 .indexer
23 .as_ref()
24 .ok_or(IndexerError::NotInitialized)?
25 .get_validity_proof(hashes, new_addresses_with_trees, config)
26 .await?)
27 }
28
29 async fn get_indexer_slot(&self, config: Option<RetryConfig>) -> Result<u64, IndexerError> {
30 Ok(self
31 .indexer
32 .as_ref()
33 .ok_or(IndexerError::NotInitialized)?
34 .get_indexer_slot(config)
35 .await?)
36 }
37
38 async fn get_multiple_compressed_account_proofs(
39 &self,
40 hashes: Vec<[u8; 32]>,
41 config: Option<IndexerRpcConfig>,
42 ) -> Result<Response<Items<MerkleProof>>, IndexerError> {
43 Ok(self
44 .indexer
45 .as_ref()
46 .ok_or(IndexerError::NotInitialized)?
47 .get_multiple_compressed_account_proofs(hashes, config)
48 .await?)
49 }
50
51 async fn get_compressed_accounts_by_owner(
52 &self,
53 owner: &Pubkey,
54 options: Option<GetCompressedAccountsByOwnerConfig>,
55 config: Option<IndexerRpcConfig>,
56 ) -> Result<Response<ItemsWithCursor<CompressedAccount>>, IndexerError> {
57 Ok(self
58 .indexer
59 .as_ref()
60 .ok_or(IndexerError::NotInitialized)?
61 .get_compressed_accounts_by_owner(owner, options, config)
62 .await?)
63 }
64
65 async fn get_compressed_account(
66 &self,
67 address: Address,
68 config: Option<IndexerRpcConfig>,
69 ) -> Result<Response<Option<CompressedAccount>>, IndexerError> {
70 Ok(self
71 .indexer
72 .as_ref()
73 .ok_or(IndexerError::NotInitialized)?
74 .get_compressed_account(address, config)
75 .await?)
76 }
77
78 async fn get_compressed_account_by_hash(
79 &self,
80 hash: Hash,
81 config: Option<IndexerRpcConfig>,
82 ) -> Result<Response<Option<CompressedAccount>>, IndexerError> {
83 Ok(self
84 .indexer
85 .as_ref()
86 .ok_or(IndexerError::NotInitialized)?
87 .get_compressed_account_by_hash(hash, config)
88 .await?)
89 }
90
91 async fn get_compressed_balance(
92 &self,
93 address: Option<Address>,
94 hash: Option<Hash>,
95 config: Option<IndexerRpcConfig>,
96 ) -> Result<Response<u64>, IndexerError> {
97 Ok(self
98 .indexer
99 .as_ref()
100 .ok_or(IndexerError::NotInitialized)?
101 .get_compressed_balance(address, hash, config)
102 .await?)
103 }
104
105 async fn get_compressed_token_account_balance(
106 &self,
107 address: Option<Address>,
108 hash: Option<Hash>,
109 config: Option<IndexerRpcConfig>,
110 ) -> Result<Response<u64>, IndexerError> {
111 Ok(self
112 .indexer
113 .as_ref()
114 .ok_or(IndexerError::NotInitialized)?
115 .get_compressed_token_account_balance(address, hash, config)
116 .await?)
117 }
118
119 async fn get_multiple_compressed_accounts(
120 &self,
121 addresses: Option<Vec<Address>>,
122 hashes: Option<Vec<Hash>>,
123 config: Option<IndexerRpcConfig>,
124 ) -> Result<Response<Items<Option<CompressedAccount>>>, IndexerError> {
125 Ok(self
126 .indexer
127 .as_ref()
128 .ok_or(IndexerError::NotInitialized)?
129 .get_multiple_compressed_accounts(addresses, hashes, config)
130 .await?)
131 }
132
133 async fn get_compressed_token_balances_by_owner_v2(
134 &self,
135 owner: &Pubkey,
136 options: Option<GetCompressedTokenAccountsByOwnerOrDelegateOptions>,
137 config: Option<IndexerRpcConfig>,
138 ) -> Result<Response<ItemsWithCursor<TokenBalance>>, IndexerError> {
139 Ok(self
140 .indexer
141 .as_ref()
142 .ok_or(IndexerError::NotInitialized)?
143 .get_compressed_token_balances_by_owner_v2(owner, options, config)
144 .await?)
145 }
146
147 async fn get_compression_signatures_for_account(
148 &self,
149 hash: Hash,
150 config: Option<IndexerRpcConfig>,
151 ) -> Result<Response<Items<SignatureWithMetadata>>, IndexerError> {
152 Ok(self
153 .indexer
154 .as_ref()
155 .ok_or(IndexerError::NotInitialized)?
156 .get_compression_signatures_for_account(hash, config)
157 .await?)
158 }
159
160 async fn get_multiple_new_address_proofs(
161 &self,
162 merkle_tree_pubkey: [u8; 32],
163 addresses: Vec<[u8; 32]>,
164 config: Option<IndexerRpcConfig>,
165 ) -> Result<Response<Items<NewAddressProofWithContext>>, IndexerError> {
166 Ok(self
167 .indexer
168 .as_ref()
169 .ok_or(IndexerError::NotInitialized)?
170 .get_multiple_new_address_proofs(merkle_tree_pubkey, addresses, config)
171 .await?)
172 }
173
174 async fn get_queue_elements(
175 &mut self,
176 merkle_tree_pubkey: [u8; 32],
177 options: QueueElementsV2Options,
178 config: Option<IndexerRpcConfig>,
179 ) -> Result<Response<QueueElementsResult>, IndexerError> {
180 Ok(self
181 .indexer
182 .as_mut()
183 .ok_or(IndexerError::NotInitialized)?
184 .get_queue_elements(merkle_tree_pubkey, options, config)
185 .await?)
186 }
187
188 async fn get_queue_leaf_indices(
189 &self,
190 merkle_tree_pubkey: [u8; 32],
191 limit: u16,
192 start_index: Option<u64>,
193 config: Option<IndexerRpcConfig>,
194 ) -> Result<Response<Items<QueueLeafIndex>>, IndexerError> {
195 Ok(self
196 .indexer
197 .as_ref()
198 .ok_or(IndexerError::NotInitialized)?
199 .get_queue_leaf_indices(merkle_tree_pubkey, limit, start_index, 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_compression_signatures_for_address(
256 &self,
257 address: &[u8; 32],
258 options: Option<PaginatedOptions>,
259 config: Option<IndexerRpcConfig>,
260 ) -> Result<Response<ItemsWithCursor<SignatureWithMetadata>>, IndexerError> {
261 Ok(self
262 .indexer
263 .as_ref()
264 .ok_or(IndexerError::NotInitialized)?
265 .get_compression_signatures_for_address(address, options, config)
266 .await?)
267 }
268
269 async fn get_compression_signatures_for_owner(
270 &self,
271 owner: &Pubkey,
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_owner(owner, options, config)
280 .await?)
281 }
282
283 async fn get_compression_signatures_for_token_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_token_owner(owner, options, config)
294 .await?)
295 }
296
297 async fn get_indexer_health(&self, config: Option<RetryConfig>) -> Result<bool, IndexerError> {
298 Ok(self
299 .indexer
300 .as_ref()
301 .ok_or(IndexerError::NotInitialized)?
302 .get_indexer_health(config)
303 .await?)
304 }
305}