Skip to content

Commit

Permalink
refactor: move PhotonIndexer to light-client crate
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeytimoshin committed Jan 27, 2025
1 parent 319eb43 commit d532c7e
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 29 deletions.
5 changes: 3 additions & 2 deletions forester/src/indexer_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use std::{any::Any, sync::Arc};
use async_trait::async_trait;
use forester_utils::forester_epoch::TreeAccounts;
use light_client::{
indexer::{Indexer, StateMerkleTreeAccounts, StateMerkleTreeBundle},
indexer::{
photon_indexer::PhotonIndexer, Indexer, StateMerkleTreeAccounts, StateMerkleTreeBundle,
},
rpc::RpcConnection,
};
use light_hasher::Poseidon;
Expand All @@ -17,7 +19,6 @@ use tracing::info;

use crate::{
errors::ForesterError,
photon_indexer::PhotonIndexer,
rollover::{perform_address_merkle_tree_rollover, perform_state_merkle_tree_rollover_forester},
ForesterConfig,
};
Expand Down
1 change: 0 additions & 1 deletion forester/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ pub mod helius_priority_fee_types;
mod indexer_type;
pub mod metrics;
pub mod pagerduty;
pub mod photon_indexer;
pub mod pubsub_client;
pub mod queue_helpers;
pub mod rollover;
Expand Down
6 changes: 4 additions & 2 deletions forester/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ use forester::{
errors::ForesterError,
forester_status,
metrics::register_metrics,
photon_indexer::PhotonIndexer,
run_pipeline,
telemetry::setup_telemetry,
ForesterConfig,
};
use light_client::rpc::{RpcConnection, SolanaRpcConnection};
use light_client::{
indexer::photon_indexer::PhotonIndexer,
rpc::{RpcConnection, SolanaRpcConnection},
};
use tokio::{
signal::ctrl_c,
sync::{mpsc, oneshot},
Expand Down
7 changes: 0 additions & 7 deletions forester/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ use light_registry::{
};
use tracing::debug;

pub fn decode_hash(account: &str) -> [u8; 32] {
let bytes = bs58::decode(account).into_vec().unwrap();
let mut arr = [0u8; 32];
arr.copy_from_slice(&bytes);
arr
}

pub async fn get_protocol_config<R: RpcConnection>(rpc: &mut R) -> ProtocolConfig {
let authority_pda = get_protocol_config_pda_address();
let protocol_config_account = rpc
Expand Down
3 changes: 1 addition & 2 deletions forester/tests/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ use account_compression::initialize_address_merkle_tree::Pubkey;
use forester::{
config::{ExternalServicesConfig, GeneralConfig},
metrics::register_metrics,
photon_indexer::PhotonIndexer,
telemetry::setup_telemetry,
ForesterConfig,
};
use light_client::{
indexer::{Indexer, IndexerError, NewAddressProofWithContext},
indexer::{photon_indexer::PhotonIndexer, Indexer, IndexerError, NewAddressProofWithContext},
rpc::RpcConnection,
};
use light_program_test::{indexer::TestIndexerExtensions, test_env::get_test_env_accounts};
Expand Down
2 changes: 2 additions & 0 deletions sdk-libs/client/src/indexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use thiserror::Error;

use crate::rpc::RpcConnection;

pub mod photon_indexer;

#[derive(Error, Debug)]
pub enum IndexerError {
#[error("RPC Error: {0}")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
use std::fmt::Debug;

use account_compression::initialize_address_merkle_tree::Pubkey;
use async_trait::async_trait;
use light_client::{
indexer::{
AddressMerkleTreeBundle, Indexer, IndexerError, LeafIndexInfo, MerkleProof,
NewAddressProofWithContext, ProofOfLeaf,
},
rpc::RpcConnection,
};
use light_sdk::proof::ProofRpcResult;
use photon_api::{
apis::configuration::{ApiKey, Configuration},
models::{AddressWithTree, GetCompressedAccountsByOwnerPostRequestParams},
};
use solana_program::pubkey::Pubkey;
use solana_sdk::bs58;
use tracing::debug;

use crate::utils::decode_hash;
use crate::{
indexer::{
AddressMerkleTreeBundle, Indexer, IndexerError, LeafIndexInfo, MerkleProof,
NewAddressProofWithContext, ProofOfLeaf,
},
rpc::RpcConnection,
};

pub struct PhotonIndexer<R: RpcConnection> {
configuration: Configuration,
Expand Down Expand Up @@ -74,11 +72,11 @@ impl<R: RpcConnection> Indexer<R> for PhotonIndexer<R> {
) -> ProofRpcResult {
todo!()
}

async fn get_multiple_compressed_account_proofs(
&self,
hashes: Vec<String>,
) -> Result<Vec<MerkleProof>, IndexerError> {
debug!("Getting proofs for {:?}", hashes);
let request: photon_api::models::GetMultipleCompressedAccountProofsPostRequest =
photon_api::models::GetMultipleCompressedAccountProofsPostRequest {
params: hashes,
Expand Down Expand Up @@ -174,16 +172,12 @@ impl<R: RpcConnection> Indexer<R> for PhotonIndexer<R> {
..Default::default()
};

debug!("Request: {:?}", request);

let result = photon_api::apis::default_api::get_multiple_new_address_proofs_v2_post(
&self.configuration,
request,
)
.await;

debug!("Response: {:?}", result);

if result.is_err() {
return Err(IndexerError::Custom(result.err().unwrap().to_string()));
}
Expand Down Expand Up @@ -252,3 +246,10 @@ impl<R: RpcConnection> Indexer<R> for PhotonIndexer<R> {
todo!()
}
}

fn decode_hash(account: &str) -> [u8; 32] {
let bytes = bs58::decode(account).into_vec().unwrap();
let mut arr = [0u8; 32];
arr.copy_from_slice(&bytes);
arr
}

0 comments on commit d532c7e

Please sign in to comment.