light_client/indexer/
indexer_trait.rs

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