light_client/indexer/
indexer_trait.rs

1use async_trait::async_trait;
2use solana_pubkey::Pubkey;
3
4use super::{
5    response::{Items, ItemsWithCursor, Response},
6    types::{
7        CompressedAccount, CompressedTokenAccount, OwnerBalance, QueueElementsResult,
8        QueueInfoResult, SignatureWithMetadata, TokenBalance, ValidityProofWithContext,
9    },
10    Address, AddressWithTree, BatchAddressUpdateIndexerResponse,
11    GetCompressedAccountsByOwnerConfig, GetCompressedTokenAccountsByOwnerOrDelegateOptions, Hash,
12    IndexerError, IndexerRpcConfig, MerkleProof, NewAddressProofWithContext, PaginatedOptions,
13    RetryConfig,
14};
15// TODO: remove all references in input types.
16#[async_trait]
17pub trait Indexer: std::marker::Send + std::marker::Sync {
18    /// Returns the compressed account with the given address or hash.
19    async fn get_compressed_account(
20        &self,
21        address: Address,
22        config: Option<IndexerRpcConfig>,
23    ) -> Result<Response<Option<CompressedAccount>>, IndexerError>;
24
25    /// Returns the compressed account with the given address or hash.
26    async fn get_compressed_account_by_hash(
27        &self,
28        hash: Hash,
29        config: Option<IndexerRpcConfig>,
30    ) -> Result<Response<Option<CompressedAccount>>, IndexerError>;
31
32    /// Returns the owner’s compressed accounts.
33    async fn get_compressed_accounts_by_owner(
34        &self,
35        owner: &Pubkey,
36        options: Option<GetCompressedAccountsByOwnerConfig>,
37        config: Option<IndexerRpcConfig>,
38    ) -> Result<Response<ItemsWithCursor<CompressedAccount>>, IndexerError>;
39
40    /// Returns the balance for the compressed account with the given address or hash.
41    async fn get_compressed_balance(
42        &self,
43        address: Option<Address>,
44        hash: Option<Hash>,
45        config: Option<IndexerRpcConfig>,
46    ) -> Result<Response<u64>, IndexerError>;
47
48    /// Returns the total balance of the owner’s compressed accounts.
49    async fn get_compressed_balance_by_owner(
50        &self,
51        owner: &Pubkey,
52        config: Option<IndexerRpcConfig>,
53    ) -> Result<Response<u64>, IndexerError>;
54
55    /// Returns the owner balances for a given mint in descending order.
56    async fn get_compressed_mint_token_holders(
57        &self,
58        mint: &Pubkey,
59        options: Option<PaginatedOptions>,
60        config: Option<IndexerRpcConfig>,
61    ) -> Result<Response<ItemsWithCursor<OwnerBalance>>, IndexerError>;
62
63    /// Returns the balance for a given token account.
64    async fn get_compressed_token_account_balance(
65        &self,
66        address: Option<Address>,
67        hash: Option<Hash>,
68        config: Option<IndexerRpcConfig>,
69    ) -> Result<Response<u64>, IndexerError>;
70
71    /// Returns the compressed token accounts that are partially or fully delegated to the given delegate.
72    async fn get_compressed_token_accounts_by_delegate(
73        &self,
74        delegate: &Pubkey,
75        options: Option<GetCompressedTokenAccountsByOwnerOrDelegateOptions>,
76        config: Option<IndexerRpcConfig>,
77    ) -> Result<Response<ItemsWithCursor<CompressedTokenAccount>>, IndexerError>;
78
79    async fn get_compressed_token_accounts_by_owner(
80        &self,
81        owner: &Pubkey,
82        options: Option<GetCompressedTokenAccountsByOwnerOrDelegateOptions>,
83        config: Option<IndexerRpcConfig>,
84    ) -> Result<Response<ItemsWithCursor<CompressedTokenAccount>>, IndexerError>;
85
86    /// Returns the token balances for a given owner.
87    async fn get_compressed_token_balances_by_owner_v2(
88        &self,
89        owner: &Pubkey,
90        options: Option<GetCompressedTokenAccountsByOwnerOrDelegateOptions>,
91        config: Option<IndexerRpcConfig>,
92    ) -> Result<Response<ItemsWithCursor<TokenBalance>>, IndexerError>;
93
94    /// Returns the token balances for a given owner.
95    async fn get_compression_signatures_for_account(
96        &self,
97        hash: Hash,
98        config: Option<IndexerRpcConfig>,
99    ) -> Result<Response<Items<SignatureWithMetadata>>, IndexerError>;
100
101    /// Return the signatures of the transactions that
102    /// closed or opened a compressed account with the given address.
103    async fn get_compression_signatures_for_address(
104        &self,
105        address: &[u8; 32],
106        options: Option<PaginatedOptions>,
107        config: Option<IndexerRpcConfig>,
108    ) -> Result<Response<ItemsWithCursor<SignatureWithMetadata>>, IndexerError>;
109
110    /// Returns the signatures of the transactions that
111    /// have modified an owner’s compressed accounts.
112    async fn get_compression_signatures_for_owner(
113        &self,
114        owner: &Pubkey,
115        options: Option<PaginatedOptions>,
116        config: Option<IndexerRpcConfig>,
117    ) -> Result<Response<ItemsWithCursor<SignatureWithMetadata>>, IndexerError>;
118
119    /// Returns the signatures of the transactions that
120    /// have modified an owner’s compressed token accounts.
121    async fn get_compression_signatures_for_token_owner(
122        &self,
123        owner: &Pubkey,
124        options: Option<PaginatedOptions>,
125        config: Option<IndexerRpcConfig>,
126    ) -> Result<Response<ItemsWithCursor<SignatureWithMetadata>>, IndexerError>;
127
128    /// Returns an error if the indexer is stale
129    /// by more than a configurable number of blocks.
130    /// Otherwise, it returns ok.
131    async fn get_indexer_health(&self, config: Option<RetryConfig>) -> Result<bool, IndexerError>;
132
133    /// Returns the slot of the last block indexed by the indexer.
134    async fn get_indexer_slot(&self, config: Option<RetryConfig>) -> Result<u64, IndexerError>;
135
136    // /// Returns the signatures of the latest transactions that used the compression program.
137    // async fn getLatestCompressionSignatures
138
139    // /// Returns the signatures of the latest transactions that are not voting transactions.
140    // getLatestNonVotingSignatures
141
142    /// Returns multiple proofs used by the compression program to verify the accounts’ validity.
143    async fn get_multiple_compressed_account_proofs(
144        &self,
145        hashes: Vec<[u8; 32]>,
146        config: Option<IndexerRpcConfig>,
147    ) -> Result<Response<Items<MerkleProof>>, IndexerError>;
148
149    /// Returns multiple compressed accounts with the given addresses or hashes.
150    async fn get_multiple_compressed_accounts(
151        &self,
152        addresses: Option<Vec<Address>>,
153        hashes: Option<Vec<Hash>>,
154        config: Option<IndexerRpcConfig>,
155    ) -> Result<Response<Items<Option<CompressedAccount>>>, IndexerError>;
156
157    /// Returns proofs that the new addresses are not taken already and can be created.
158    async fn get_multiple_new_address_proofs(
159        &self,
160        merkle_tree_pubkey: [u8; 32],
161        addresses: Vec<[u8; 32]>,
162        config: Option<IndexerRpcConfig>,
163    ) -> Result<Response<Items<NewAddressProofWithContext>>, IndexerError>;
164
165    /// Returns a single ZK Proof used by the compression program
166    /// to verify that the given accounts are valid and that
167    /// the new addresses can be created.
168    async fn get_validity_proof(
169        &self,
170        hashes: Vec<Hash>,
171        new_addresses_with_trees: Vec<AddressWithTree>,
172        config: Option<IndexerRpcConfig>,
173    ) -> Result<Response<ValidityProofWithContext>, IndexerError>;
174
175    // TODO: in different pr:
176    //      replace zkp_batch_size with PaginatedOptions
177    //      - return type should be ItemsWithCursor
178    async fn get_address_queue_with_proofs(
179        &mut self,
180        merkle_tree_pubkey: &Pubkey,
181        zkp_batch_size: u16,
182        start_offset: Option<u64>,
183        config: Option<IndexerRpcConfig>,
184    ) -> Result<Response<BatchAddressUpdateIndexerResponse>, IndexerError>;
185
186    // TODO: in different pr:
187    //      replace num_elements & start_queue_index with PaginatedOptions
188    //      - return type should be ItemsWithCursor
189    /// Returns queue elements from the queue with the given merkle tree pubkey.
190    /// Can fetch from output queue (append), input queue (nullify), or both atomically.
191    /// For input queues account compression program does not store queue elements in the
192    /// account data but only emits these in the public transaction event. The
193    /// indexer needs the queue elements to create batch update proofs.
194    async fn get_queue_elements(
195        &mut self,
196        merkle_tree_pubkey: [u8; 32],
197        output_queue_start_index: Option<u64>,
198        output_queue_limit: Option<u16>,
199        input_queue_start_index: Option<u64>,
200        input_queue_limit: Option<u16>,
201        config: Option<IndexerRpcConfig>,
202    ) -> Result<Response<QueueElementsResult>, IndexerError>;
203
204    /// Returns information about all queues in the system.
205    /// Includes tree pubkey, queue pubkey, queue type, and queue size for each queue.
206    async fn get_queue_info(
207        &self,
208        config: Option<IndexerRpcConfig>,
209    ) -> Result<Response<QueueInfoResult>, IndexerError>;
210
211    /// V2: Returns queue elements with deduplicated nodes for efficient staging tree construction.
212    /// Supports output queue, input queue, and address queue.
213    async fn get_queue_elements_v2(
214        &mut self,
215        merkle_tree_pubkey: [u8; 32],
216        options: super::QueueElementsV2Options,
217        config: Option<IndexerRpcConfig>,
218    ) -> Result<Response<super::QueueElementsV2Result>, IndexerError>;
219    async fn get_subtrees(
220        &self,
221        merkle_tree_pubkey: [u8; 32],
222        config: Option<IndexerRpcConfig>,
223    ) -> Result<Response<Items<[u8; 32]>>, IndexerError>;
224}