Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Test SDK which uses Photon indexer #1216

Draft
wants to merge 3 commits into
base: vadorovsky/new-photon-indexer
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,14 @@ thiserror = "1.0"

# Light Protocol
light-client = { path = "client", version = "0.8.0" }
light-indexed-merkle-tree = { path = "merkle-tree/indexed", version = "1.0.0" }
light-sdk = { path = "sdk", version = "0.8.0" }
photon-api = { path = "photon-api" }

# Math and crypto
bs58 = "0.4.0"
num-bigint = "0.4.6"

[patch.crates-io]
"solana-account-decoder" = { git = "https://github.com/lightprotocol/agave", branch = "v1.18.22-enforce-cpi-tracking" }
"solana-accounts-db" = { git = "https://github.com/lightprotocol/agave", branch = "v1.18.22-enforce-cpi-tracking" }
Expand Down
7 changes: 7 additions & 0 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@ solana-transaction-status = { workspace = true }
# Anchor compatibility
borsh = { workspace = true }

# Light Protocol
light-sdk = { workspace = true }
photon-api = { workspace = true }

# Async ecosystem
tokio = { workspace = true }
async-trait = { workspace = true }
bb8 = { workspace = true }

# Math and crypto
bs58 = { workspace = true }

log = { workspace = true }
thiserror = { workspace = true }
77 changes: 76 additions & 1 deletion client/src/indexer/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,76 @@
pub trait Indexer: Sync + Send + Debug + 'static {}
use std::{fmt::Debug, future::Future};

use light_sdk::{
address::AddressWithMerkleContext,
compressed_account::CompressedAccountWithMerkleContext,
proof::{MerkleProof, NewAddressProofWithContext, ProofRpcResult},
};
use solana_sdk::pubkey::Pubkey;
use thiserror::Error;

pub mod photon;

#[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(transparent)]
// HashSetError(#[from] HashSetError),
// #[error(transparent)]
// PhotonApiError(PhotonApiErrorWrapper),
// #[error("error: {0:?}")]
// Custom(String),
#[error("unknown error")]
Unknown,

#[error("indexer returned an empty result")]
EmptyResult,

#[error("failed to hash a compressed account")]
AccountHash,
}

/// Format of hashes.
///
/// Depending on the context, it's better to treat hashes either as arrays or
/// as strings.
///
/// Photon API takes hashes as strings.
///
/// In Solana program tests it's more convenient to operate on arrays. The
/// `Array` variant is being converted to strings by indexer implementations,
/// so the conversion doesn't have to be done independently in tests.
///
/// In forester, which only uses Photon, it makes more sense to just use
/// strings and avoid conversions.
#[derive(Debug)]
pub enum Hashes<'a> {
Array(&'a [[u8; 32]]),
String(&'a [String]),
}

pub trait Indexer: Sync + Send + Debug + 'static {
fn get_compressed_accounts_by_owner(
&self,
owner: &Pubkey,
) -> impl Future<Output = Result<Vec<CompressedAccountWithMerkleContext>, IndexerError>> + Send + Sync;

fn get_multiple_compressed_account_proofs<'a>(
&self,
hashes: Hashes<'a>,
) -> impl Future<Output = Result<Vec<MerkleProof>, IndexerError>> + Send + Sync;

fn get_multiple_new_address_proofs(
&self,
merkle_tree_pubkey: &Pubkey,
addresses: &[[u8; 32]],
) -> impl Future<Output = Result<Vec<NewAddressProofWithContext>, IndexerError>> + Send + Sync;

fn get_validity_proof(
&self,
compressed_accounts: &[CompressedAccountWithMerkleContext],
new_addresses: &[AddressWithMerkleContext],
) -> impl Future<Output = Result<ProofRpcResult, IndexerError>> + Send + Sync;
}
Loading