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, QueueInfoResult,
8        SignatureWithMetadata, TokenBalance, ValidityProofWithContext,
9    },
10    Address, AddressWithTree, GetCompressedAccountsByOwnerConfig,
11    GetCompressedTokenAccountsByOwnerOrDelegateOptions, Hash, IndexerError, IndexerRpcConfig,
12    MerkleProof, NewAddressProofWithContext, PaginatedOptions, QueueElementsV2Options, RetryConfig,
13};
14use crate::indexer::QueueElementsResult;
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    /// Returns queue elements with deduplicated nodes for efficient staging tree construction.
176    /// Supports output queue, input queue, and address queue.
177    async fn get_queue_elements(
178        &mut self,
179        merkle_tree_pubkey: [u8; 32],
180        options: QueueElementsV2Options,
181        config: Option<IndexerRpcConfig>,
182    ) -> Result<Response<QueueElementsResult>, IndexerError>;
183
184    /// Returns information about all queues in the system.
185    /// Includes tree pubkey, queue pubkey, queue type, and queue size for each queue.
186    async fn get_queue_info(
187        &self,
188        config: Option<IndexerRpcConfig>,
189    ) -> Result<Response<QueueInfoResult>, IndexerError>;
190
191    async fn get_subtrees(
192        &self,
193        merkle_tree_pubkey: [u8; 32],
194        config: Option<IndexerRpcConfig>,
195    ) -> Result<Response<Items<[u8; 32]>>, IndexerError>;
196}