-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Remove hard dependency on
light-system-program
in SDK (#1230
) * refactor: Remove hard dependency on `light-system-program` in SDK First of all, add more types to the SDK, which are going to be used by third-party applications, which were until now defined in program crates: - `address` - `NewAddressParams` - `NewAddressParamsPacked` - `compressed_account` - `CompressedAccount` - `CompressedAccountData` - `CompressedAccountWithMerkleContext` - `PackedCompressedAccountWithMerkleContext` - `OutputCompressedAccountWithPackedContext` - `event` - `MerkleTreeSequenceNumber` - `PublicTransactionEvent` - `merkle_context` - `QueueIndex` - `MerkleContext` - `PackedMerkleContext` - `proof` - `CompressedProof` - `ProofRpcResult` - `verify` - `CompressedCpiContext` - `InstructionDataInvokeCpi` Hide the imports from `light_system_program` behind a feature flag. The long-term plan is to remove them all together. Provide a dependency-free, tinier implementation of `TestIndexer` in the `light-client` crate. * Remove commented code * Add a check for light-system-program ID
- Loading branch information
1 parent
09d605a
commit 298e10f
Showing
37 changed files
with
1,958 additions
and
302 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,110 @@ | ||
pub trait Indexer: Sync + Send + Debug + 'static {} | ||
use std::{fmt::Debug, future::Future}; | ||
|
||
use light_concurrent_merkle_tree::light_hasher::Poseidon; | ||
use light_indexed_merkle_tree::{ | ||
array::{IndexedArray, IndexedElement}, | ||
reference::IndexedMerkleTree, | ||
}; | ||
use light_merkle_tree_reference::MerkleTree; | ||
use light_sdk::{ | ||
compressed_account::CompressedAccountWithMerkleContext, event::PublicTransactionEvent, | ||
proof::ProofRpcResult, token::TokenDataWithMerkleContext, | ||
}; | ||
use num_bigint::BigUint; | ||
use solana_sdk::pubkey::Pubkey; | ||
use thiserror::Error; | ||
|
||
use crate::rpc::RpcConnection; | ||
|
||
pub mod test_indexer; | ||
|
||
#[derive(Error, Debug)] | ||
pub enum IndexerError { | ||
#[error("RPC Error: {0}")] | ||
RpcError(#[from] solana_client::client_error::ClientError), | ||
#[error("failed to deserialize account data")] | ||
DeserializeError(#[from] solana_sdk::program_error::ProgramError), | ||
#[error("failed to copy merkle tree")] | ||
CopyMerkleTreeError(#[from] std::io::Error), | ||
#[error("error: {0:?}")] | ||
Custom(String), | ||
#[error("unknown error")] | ||
Unknown, | ||
} | ||
|
||
pub trait Indexer<R: RpcConnection>: Sync + Send + Debug + 'static { | ||
fn add_event_and_compressed_accounts( | ||
&mut self, | ||
event: &PublicTransactionEvent, | ||
) -> ( | ||
Vec<CompressedAccountWithMerkleContext>, | ||
Vec<TokenDataWithMerkleContext>, | ||
); | ||
|
||
fn create_proof_for_compressed_accounts( | ||
&mut self, | ||
compressed_accounts: Option<&[[u8; 32]]>, | ||
state_merkle_tree_pubkeys: Option<&[Pubkey]>, | ||
new_addresses: Option<&[[u8; 32]]>, | ||
address_merkle_tree_pubkeys: Option<Vec<Pubkey>>, | ||
rpc: &mut R, | ||
) -> impl Future<Output = ProofRpcResult>; | ||
|
||
fn get_compressed_accounts_by_owner( | ||
&self, | ||
owner: &Pubkey, | ||
) -> Vec<CompressedAccountWithMerkleContext>; | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct MerkleProof { | ||
pub hash: String, | ||
pub leaf_index: u64, | ||
pub merkle_tree: String, | ||
pub proof: Vec<[u8; 32]>, | ||
pub root_seq: u64, | ||
} | ||
|
||
// For consistency with the Photon API. | ||
#[derive(Clone, Default, Debug, PartialEq)] | ||
pub struct NewAddressProofWithContext { | ||
pub merkle_tree: [u8; 32], | ||
pub root: [u8; 32], | ||
pub root_seq: u64, | ||
pub low_address_index: u64, | ||
pub low_address_value: [u8; 32], | ||
pub low_address_next_index: u64, | ||
pub low_address_next_value: [u8; 32], | ||
pub low_address_proof: [[u8; 32]; 16], | ||
pub new_low_element: Option<IndexedElement<usize>>, | ||
pub new_element: Option<IndexedElement<usize>>, | ||
pub new_element_next_value: Option<BigUint>, | ||
} | ||
|
||
#[derive(Debug, Clone, Copy, Ord, PartialOrd, Eq, PartialEq)] | ||
pub struct StateMerkleTreeAccounts { | ||
pub merkle_tree: Pubkey, | ||
pub nullifier_queue: Pubkey, | ||
pub cpi_context: Pubkey, | ||
} | ||
|
||
#[derive(Debug, Clone, Copy)] | ||
pub struct AddressMerkleTreeAccounts { | ||
pub merkle_tree: Pubkey, | ||
pub queue: Pubkey, | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct StateMerkleTreeBundle { | ||
pub rollover_fee: u64, | ||
pub merkle_tree: Box<MerkleTree<Poseidon>>, | ||
pub accounts: StateMerkleTreeAccounts, | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct AddressMerkleTreeBundle { | ||
pub rollover_fee: u64, | ||
pub merkle_tree: Box<IndexedMerkleTree<Poseidon, usize>>, | ||
pub indexed_array: Box<IndexedArray<Poseidon, usize>>, | ||
pub accounts: AddressMerkleTreeAccounts, | ||
} |
Oops, something went wrong.