Skip to content
Merged
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
3 changes: 2 additions & 1 deletion scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ install_photon() {
if [ "$photon_installed" = false ] || [ "$photon_correct_version" = false ]; then
echo "Installing Photon indexer (version $expected_version)..."
# Use git commit for now as specified in constants.ts
cargo install --git https://github.com/helius-labs/photon.git --rev b0ad386858384c22b4bb6a3bbbcd6a65911dac68 --locked --force
# Allow dead code warnings for external dependency compilation
RUSTFLAGS="-A dead-code" cargo install --git https://github.com/helius-labs/photon.git --rev b0ad386858384c22b4bb6a3bbbcd6a65911dac68 --locked --force
log "photon"
else
echo "Photon already installed with correct version, skipping..."
Expand Down
6 changes: 3 additions & 3 deletions sdk-libs/client/src/indexer/indexer_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ pub trait Indexer: std::marker::Send + std::marker::Sync {
&self,
address: Address,
config: Option<IndexerRpcConfig>,
) -> Result<Response<CompressedAccount>, IndexerError>;
) -> Result<Response<Option<CompressedAccount>>, IndexerError>;

/// Returns the compressed account with the given address or hash.
async fn get_compressed_account_by_hash(
&self,
hash: Hash,
config: Option<IndexerRpcConfig>,
) -> Result<Response<CompressedAccount>, IndexerError>;
) -> Result<Response<Option<CompressedAccount>>, IndexerError>;

/// Returns the owner’s compressed accounts.
async fn get_compressed_accounts_by_owner(
Expand Down Expand Up @@ -153,7 +153,7 @@ pub trait Indexer: std::marker::Send + std::marker::Sync {
addresses: Option<Vec<Address>>,
hashes: Option<Vec<Hash>>,
config: Option<IndexerRpcConfig>,
) -> Result<Response<Items<CompressedAccount>>, IndexerError>;
) -> Result<Response<Items<Option<CompressedAccount>>>, IndexerError>;

/// Returns proofs that the new addresses are not taken already and can be created.
async fn get_multiple_new_address_proofs(
Expand Down
31 changes: 16 additions & 15 deletions sdk-libs/client/src/indexer/photon_indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl Indexer for PhotonIndexer {
&self,
address: Address,
config: Option<IndexerRpcConfig>,
) -> Result<Response<CompressedAccount>, IndexerError> {
) -> Result<Response<Option<CompressedAccount>>, IndexerError> {
let config = config.unwrap_or_default();
self.retry(config.retry_config, || async {
let params = self.build_account_params(Some(address), None)?;
Expand All @@ -201,11 +201,10 @@ impl Indexer for PhotonIndexer {
if api_response.context.slot < config.slot {
return Err(IndexerError::IndexerNotSyncedToSlot);
}
let account_data = api_response
.value
.ok_or(IndexerError::AccountNotFound)
.map(|boxed| *boxed)?;
let account = CompressedAccount::try_from(&account_data)?;
let account = match api_response.value {
Some(boxed) => Some(CompressedAccount::try_from(&*boxed)?),
None => None,
};

Ok(Response {
context: Context {
Expand All @@ -221,7 +220,7 @@ impl Indexer for PhotonIndexer {
&self,
hash: Hash,
config: Option<IndexerRpcConfig>,
) -> Result<Response<CompressedAccount>, IndexerError> {
) -> Result<Response<Option<CompressedAccount>>, IndexerError> {
let config = config.unwrap_or_default();
self.retry(config.retry_config, || async {
let params = self.build_account_params(None, Some(hash))?;
Expand All @@ -243,11 +242,10 @@ impl Indexer for PhotonIndexer {
if api_response.context.slot < config.slot {
return Err(IndexerError::IndexerNotSyncedToSlot);
}
let account_data = api_response
.value
.ok_or(IndexerError::AccountNotFound)
.map(|boxed| *boxed)?;
let account = CompressedAccount::try_from(&account_data)?;
let account = match api_response.value {
Some(boxed) => Some(CompressedAccount::try_from(&*boxed)?),
None => None,
};

Ok(Response {
context: Context {
Expand Down Expand Up @@ -1209,7 +1207,7 @@ impl Indexer for PhotonIndexer {
addresses: Option<Vec<Address>>,
hashes: Option<Vec<Hash>>,
config: Option<IndexerRpcConfig>,
) -> Result<Response<Items<CompressedAccount>>, IndexerError> {
) -> Result<Response<Items<Option<CompressedAccount>>>, IndexerError> {
let config = config.unwrap_or_default();
self.retry(config.retry_config, || async {
let hashes = hashes.clone();
Expand Down Expand Up @@ -1242,8 +1240,11 @@ impl Indexer for PhotonIndexer {
.value
.items
.iter()
.map(CompressedAccount::try_from)
.collect::<Result<Vec<CompressedAccount>, IndexerError>>()?;
.map(|account_opt| match account_opt {
Some(account) => CompressedAccount::try_from(account).map(Some),
None => Ok(None),
})
.collect::<Result<Vec<Option<CompressedAccount>>, IndexerError>>()?;

Ok(Response {
context: Context {
Expand Down
6 changes: 3 additions & 3 deletions sdk-libs/client/src/rpc/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl Indexer for LightClient {
&self,
address: Address,
config: Option<IndexerRpcConfig>,
) -> Result<Response<CompressedAccount>, IndexerError> {
) -> Result<Response<Option<CompressedAccount>>, IndexerError> {
Ok(self
.indexer
.as_ref()
Expand All @@ -80,7 +80,7 @@ impl Indexer for LightClient {
&self,
hash: Hash,
config: Option<IndexerRpcConfig>,
) -> Result<Response<CompressedAccount>, IndexerError> {
) -> Result<Response<Option<CompressedAccount>>, IndexerError> {
Ok(self
.indexer
.as_ref()
Expand Down Expand Up @@ -136,7 +136,7 @@ impl Indexer for LightClient {
addresses: Option<Vec<Address>>,
hashes: Option<Vec<Hash>>,
config: Option<IndexerRpcConfig>,
) -> Result<Response<Items<CompressedAccount>>, IndexerError> {
) -> Result<Response<Items<Option<CompressedAccount>>>, IndexerError> {
Ok(self
.indexer
.as_ref()
Expand Down
4 changes: 2 additions & 2 deletions sdk-libs/photon-api/src/models/account_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ use crate::models;
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct AccountList {
#[serde(rename = "items")]
pub items: Vec<models::Account>,
pub items: Vec<Option<models::Account>>,
}

impl AccountList {
pub fn new(items: Vec<models::Account>) -> AccountList {
pub fn new(items: Vec<Option<models::Account>>) -> AccountList {
AccountList { items }
}
}
74 changes: 39 additions & 35 deletions sdk-libs/program-test/src/indexer/test_indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,16 @@ impl Indexer for TestIndexer {
&self,
address: Address,
_config: Option<IndexerRpcConfig>,
) -> Result<Response<CompressedAccount>, IndexerError> {
) -> Result<Response<Option<CompressedAccount>>, IndexerError> {
let account = self
.compressed_accounts
.iter()
.find(|acc| acc.compressed_account.address == Some(address));

let account_data = account
.ok_or(IndexerError::AccountNotFound)?
.clone()
.try_into()?;
let account_data = match account {
Some(acc) => Some(acc.clone().try_into()?),
None => None,
};

Ok(Response {
context: Context {
Expand All @@ -211,7 +211,7 @@ impl Indexer for TestIndexer {
&self,
hash: Hash,
_config: Option<IndexerRpcConfig>,
) -> Result<Response<CompressedAccount>, IndexerError> {
) -> Result<Response<Option<CompressedAccount>>, IndexerError> {
let res = self
.compressed_accounts
.iter()
Expand All @@ -228,10 +228,10 @@ impl Indexer for TestIndexer {
res
};

let account_data = account
.ok_or(IndexerError::AccountNotFound)?
.clone()
.try_into()?;
let account_data = match account {
Some(acc) => Some(acc.clone().try_into()?),
None => None,
};

Ok(Response {
context: Context {
Expand Down Expand Up @@ -293,11 +293,14 @@ impl Indexer for TestIndexer {
))
}
};
let account = account_response
.value
.ok_or(IndexerError::AccountNotFound)?;
Ok(Response {
context: Context {
slot: self.get_current_slot(),
},
value: account_response.value.lamports,
value: account.lamports,
})
}

Expand Down Expand Up @@ -340,38 +343,42 @@ impl Indexer for TestIndexer {
addresses: Option<Vec<Address>>,
hashes: Option<Vec<Hash>>,
_config: Option<IndexerRpcConfig>,
) -> Result<Response<Items<CompressedAccount>>, IndexerError> {
) -> Result<Response<Items<Option<CompressedAccount>>>, IndexerError> {
match (addresses, hashes) {
(Some(addresses), _) => {
let accounts = self
.compressed_accounts
let accounts: Result<Vec<Option<CompressedAccount>>, IndexerError> = addresses
.iter()
.filter(|acc| {
acc.compressed_account
.address
.is_some_and(|addr| addresses.contains(&addr))
.map(|addr| {
self.compressed_accounts
.iter()
.find(|acc| acc.compressed_account.address == Some(*addr))
.map(|acc| acc.clone().try_into())
.transpose()
})
.map(|acc| acc.clone().try_into())
.collect::<Result<Vec<CompressedAccount>, IndexerError>>()?;
.collect();
Ok(Response {
context: Context {
slot: self.get_current_slot(),
},
value: Items { items: accounts },
value: Items { items: accounts? },
})
}
(_, Some(hashes)) => {
let accounts = self
.compressed_accounts
let accounts: Result<Vec<Option<CompressedAccount>>, IndexerError> = hashes
.iter()
.filter(|acc| acc.hash().is_ok_and(|hash| hashes.contains(&hash)))
.map(|acc| acc.clone().try_into())
.collect::<Result<Vec<CompressedAccount>, IndexerError>>()?;
.map(|hash| {
self.compressed_accounts
.iter()
.find(|acc| acc.hash() == Ok(*hash))
.map(|acc| acc.clone().try_into())
.transpose()
})
.collect();
Ok(Response {
context: Context {
slot: self.get_current_slot(),
},
value: Items { items: accounts },
value: Items { items: accounts? },
})
}
(None, None) => Err(IndexerError::InvalidParameters(
Expand Down Expand Up @@ -450,7 +457,8 @@ impl Indexer for TestIndexer {

for hash in hashes.iter() {
let account = self.get_compressed_account_by_hash(*hash, None).await?;
state_merkle_tree_pubkeys.push(account.value.tree_info.tree);
let account_data = account.value.ok_or(IndexerError::AccountNotFound)?;
state_merkle_tree_pubkeys.push(account_data.tree_info.tree);
}
let mut proof_inputs = vec![];

Expand Down Expand Up @@ -2089,13 +2097,9 @@ impl TestIndexer {
let mut state_merkle_tree_pubkeys = Vec::new();

for hash in hashes.iter() {
state_merkle_tree_pubkeys.push(
self.get_compressed_account_by_hash(*hash, None)
.await?
.value
.tree_info
.tree,
);
let account = self.get_compressed_account_by_hash(*hash, None).await?;
let account_data = account.value.ok_or(IndexerError::AccountNotFound)?;
state_merkle_tree_pubkeys.push(account_data.tree_info.tree);
}

let state_merkle_tree_pubkeys = if state_merkle_tree_pubkeys.is_empty() {
Expand Down
6 changes: 3 additions & 3 deletions sdk-libs/program-test/src/program_test/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl Indexer for LightProgramTest {
&self,
address: Address,
config: Option<IndexerRpcConfig>,
) -> Result<Response<CompressedAccount>, IndexerError> {
) -> Result<Response<Option<CompressedAccount>>, IndexerError> {
Ok(self
.indexer
.as_ref()
Expand All @@ -80,7 +80,7 @@ impl Indexer for LightProgramTest {
&self,
hash: Hash,
config: Option<IndexerRpcConfig>,
) -> Result<Response<CompressedAccount>, IndexerError> {
) -> Result<Response<Option<CompressedAccount>>, IndexerError> {
Ok(self
.indexer
.as_ref()
Expand Down Expand Up @@ -132,7 +132,7 @@ impl Indexer for LightProgramTest {
addresses: Option<Vec<Address>>,
hashes: Option<Vec<Hash>>,
config: Option<IndexerRpcConfig>,
) -> Result<Response<Items<CompressedAccount>>, IndexerError> {
) -> Result<Response<Items<Option<CompressedAccount>>>, IndexerError> {
Ok(self
.indexer
.as_ref()
Expand Down
Loading
Loading