Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeytimoshin committed Jan 28, 2025

Verified

This commit was signed with the committer’s verified signature.
stsewd Santos Gallegos
1 parent b4e21a8 commit 02fc92e
Showing 8 changed files with 35 additions and 33 deletions.
1 change: 0 additions & 1 deletion program-tests/utils/src/conversions.rs
Original file line number Diff line number Diff line change
@@ -80,7 +80,6 @@ pub fn program_to_sdk_compressed_account(
owner: program_account.owner,
lamports: program_account.lamports,
address: program_account.address,
hash: None,
data: program_account
.data
.map(program_to_sdk_compressed_account_data),
6 changes: 3 additions & 3 deletions sdk-libs/client/src/indexer/mod.rs
Original file line number Diff line number Diff line change
@@ -355,16 +355,16 @@ impl TryFrom<LocalPhotonAccount> for CompressedAccountWithMerkleContext {
address: account
.address
.map(|a| <[u8; 32]>::from_base58(&a).unwrap()),
hash: Some(<[u8; 32]>::from_base58(&account.hash)?),
lamports: account.lamports,
owner: Pubkey::from_str(&account.owner)?,
data: None,
};

if let Some(data) = account.data {
let data_decoded = base64::decode(&data.data)?;
compressed_account.data = Some(CompressedAccountData {
discriminator: data.discriminator.to_be_bytes(),
data: base64::decode(&data.data)?,
discriminator: data.discriminator.to_le_bytes(),
data: data_decoded,
data_hash: <[u8; 32]>::from_base58(&data.data_hash)?,
});
}
2 changes: 1 addition & 1 deletion sdk-libs/client/src/indexer/photon_indexer.rs
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ impl<R: RpcConnection> PhotonIndexer<R> {
pub fn get_rpc_mut(&mut self) -> &mut R {
&mut self.rpc
}

async fn rate_limited_request<F, Fut, T>(&self, operation: F) -> Result<T, IndexerError>
where
F: FnOnce() -> Fut,
18 changes: 13 additions & 5 deletions sdk-libs/client/src/rpc/solana_rpc.rs
Original file line number Diff line number Diff line change
@@ -236,8 +236,11 @@ impl SolanaRpcConnection {
)
})?;

if let Ok(parsed_data) = T::try_from_slice(data.as_slice()) {
return Ok(parsed_data);
match T::try_from_slice(data.as_slice()) {
Ok(parsed_data) => return Ok(parsed_data),
Err(e) => {
warn!("Failed to parse inner instruction: {:?}", e);
}
}
}
UiInstruction::Parsed(_) => {
@@ -382,9 +385,14 @@ impl RpcConnection for SolanaRpcConnection {

let mut parsed_event = None;
for instruction in &transaction.message.instructions {
if let Ok(e) = T::deserialize(&mut &instruction.data[..]) {
parsed_event = Some(e);
break;
match T::deserialize(&mut &instruction.data[..]) {
Ok(e) => {
parsed_event = Some(e);
break;
}
Err(e) => {
warn!("Failed to parse event: {:?}", e);
}
}
}

37 changes: 18 additions & 19 deletions sdk-libs/client/tests/rpc_client.rs
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ use light_program_test::test_env::EnvAccounts;
use light_prover_client::gnark::helpers::{
spawn_validator, LightValidatorConfig, ProofType, ProverConfig,
};
use light_sdk::event::PublicTransactionEvent;
use light_system_program::sdk::{
compressed_account::CompressedAccount, invoke::create_invoke_instruction,
};
@@ -200,7 +201,10 @@ async fn test_all_endpoints() {
.await
.unwrap();
assert_eq!(account.lamports, lamports);
assert_eq!(account.owner, indexer.get_rpc().get_payer().pubkey().to_string());
assert_eq!(
account.owner,
indexer.get_rpc().get_payer().pubkey().to_string()
);

let balance = indexer
.get_compressed_account_balance(None, Some(first_hash))
@@ -217,34 +221,29 @@ async fn test_all_endpoints() {
tx_create_compressed_account.signatures[0].to_string()
);

let token_account = &indexer
let token_accounts = &indexer
.get_compressed_token_accounts_by_owner(&pubkey, None)
.await
.unwrap()[0];
assert_eq!(token_account.token_data.mint, mint.pubkey());
assert_eq!(token_account.token_data.owner, payer_pubkey);

let balance = indexer
.get_compressed_token_account_balance(
None,
Some(
token_account
.compressed_account
.compressed_account
.hash
.unwrap(),
),
)
.await
.unwrap();
assert_eq!(balance, amount);

assert_eq!(token_accounts[0].token_data.mint, mint.pubkey());
assert_eq!(token_accounts[0].token_data.owner, payer_pubkey);

let hash = token_accounts[0].compressed_account.hash().unwrap();

let balances = indexer
.get_compressed_token_balances_by_owner(&pubkey, None)
.await
.unwrap();

assert_eq!(balances.token_balances[0].balance, amount);

let balance = indexer
.get_compressed_token_account_balance(None, Some(hash))
.await
.unwrap();
assert_eq!(balance, amount);

let hashes_str = hashes.iter().map(|h| h.to_base58()).collect();
let proofs = indexer
.get_multiple_compressed_account_proofs(hashes_str)
1 change: 0 additions & 1 deletion sdk-libs/sdk/src/account.rs
Original file line number Diff line number Diff line change
@@ -146,7 +146,6 @@ where
owner: *self.account_info.owner,
lamports: self.account_info.lamports.unwrap_or(0),
address: self.account_info.address,
hash: None,
data,
},
merkle_tree_index,
2 changes: 0 additions & 2 deletions sdk-libs/sdk/src/account_info.rs
Original file line number Diff line number Diff line change
@@ -311,7 +311,6 @@ impl<'a> LightAccountInfo<'a> {
owner: *self.owner,
lamports: input.lamports.unwrap_or(0),
address: input.address,
hash: None,
data,
},
merkle_context: input.merkle_context,
@@ -347,7 +346,6 @@ impl<'a> LightAccountInfo<'a> {
owner: *self.owner,
lamports: self.lamports.unwrap_or(0),
address: self.address,
hash: None,
data,
},
merkle_tree_index,
1 change: 0 additions & 1 deletion sdk-libs/sdk/src/compressed_account.rs
Original file line number Diff line number Diff line change
@@ -11,7 +11,6 @@ pub struct CompressedAccount {
pub owner: Pubkey,
pub lamports: u64,
pub address: Option<[u8; 32]>,
pub hash: Option<[u8; 32]>,
pub data: Option<CompressedAccountData>,
}

0 comments on commit 02fc92e

Please sign in to comment.