Skip to content

Commit 65a4d1e

Browse files
committed
fix: compile time errors
1 parent 671babe commit 65a4d1e

File tree

11 files changed

+40
-16
lines changed

11 files changed

+40
-16
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

program-libs/compressed-account/src/pubkey.rs

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use borsh::{BorshDeserialize, BorshSerialize};
22
#[cfg(feature = "bytemuck-des")]
33
use bytemuck::{Pod, Zeroable};
4-
use light_hasher::bytes::AsByteVec;
4+
use light_hasher::{to_byte_array::ToByteArray, HasherError};
55
use light_zero_copy::{borsh::Deserialize, borsh_mut::DeserializeMut, errors::ZeroCopyError};
66
use solana_program::pubkey;
77
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout, Ref, Unaligned};
@@ -140,8 +140,19 @@ impl Pubkey {
140140
}
141141
}
142142

143-
impl AsByteVec for Pubkey {
144-
fn as_byte_vec(&self) -> Vec<Vec<u8>> {
145-
vec![self.to_bytes().to_vec()]
143+
impl ToByteArray for Pubkey {
144+
const NUM_FIELDS: usize = 1;
145+
146+
fn to_byte_array(&self) -> Result<[u8; 32], HasherError> {
147+
Ok(self.to_bytes())
148+
}
149+
150+
fn to_byte_arrays<const NUM_FIELDS: usize>(
151+
&self,
152+
) -> Result<[[u8; 32]; NUM_FIELDS], HasherError> {
153+
if Self::NUM_FIELDS != NUM_FIELDS {
154+
return Err(HasherError::InvalidNumFields);
155+
}
156+
Ok([self.to_byte_array()?; NUM_FIELDS])
146157
}
147158
}

program-tests/sdk-test/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub fn update_pda(accounts: &[AccountInfo], instruction_data: &[u8]) -> Result<(
131131
// Could implement into LightInputAccountInfo. Could we derive it? #[into_light_input_account_info] (will detect whether lamports, etc exist)
132132
let input_metadata = LightInputAccountInfo::from_input_account_meta_with_address_no_lamports(
133133
&instruction_data.input_compressed_account.meta,
134-
input_my_compressed_account.hash::<Poseidon>().unwrap(),
134+
input_my_compressed_account.hash().unwrap(),
135135
)
136136
.unwrap();
137137

programs/account-compression/src/instructions/nullify_leaves.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ fn insert_nullifier<'a, 'c: 'info, 'info>(
106106
{
107107
let merkle_tree = ctx.accounts.merkle_tree.load()?;
108108

109-
if merkle_tree.metadata.associated_queue != ctx.accounts.nullifier_queue.key().into() {
109+
if merkle_tree.metadata.associated_queue != <anchor_lang::prelude::Pubkey as Into<light_compressed_account::pubkey::Pubkey>>::into(ctx.accounts.nullifier_queue.key()) {
110110
msg!(
111111
"Merkle tree and nullifier queue are not associated. Merkle tree associated nullifier queue {:?} != nullifier queue {}",
112112
merkle_tree.metadata.associated_queue,

programs/account-compression/src/instructions/update_address_merkle_tree.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ pub fn process_update_address_merkle_tree<'info>(
5656

5757
{
5858
let merkle_tree = ctx.accounts.merkle_tree.load_mut()?;
59-
if merkle_tree.metadata.associated_queue != ctx.accounts.queue.key().into() {
59+
if merkle_tree.metadata.associated_queue
60+
!= <anchor_lang::prelude::Pubkey as Into<light_compressed_account::pubkey::Pubkey>>::into(ctx.accounts.queue.key())
61+
{
6062
msg!(
6163
"Merkle tree and nullifier queue are not associated. Merkle tree associated address queue {:?} != provided queue {}",
6264
merkle_tree.metadata.associated_queue,

programs/account-compression/src/processor/insert_addresses.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ fn process_address_v1<'info>(
138138
.map_err(ProgramError::from)?;
139139
let queue = bytemuck::from_bytes::<QueueAccount>(&queue_data[8..QueueAccount::LEN]);
140140
// 3. Check queue and Merkle tree are associated.
141-
if queue.metadata.associated_merkle_tree != (*merkle_pubkey).into() {
141+
if queue.metadata.associated_merkle_tree != <anchor_lang::prelude::Pubkey as Into<light_compressed_account::pubkey::Pubkey>>::into(*merkle_pubkey) {
142142
msg!(
143143
"Queue account {:?} is not associated with Merkle tree {:?}",
144144
address_queue.key(),

programs/account-compression/src/processor/insert_nullifiers.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use anchor_lang::prelude::*;
22
use light_batched_merkle_tree::queue::BatchedQueueAccount;
3-
use light_compressed_account::instruction_data::insert_into_queues::InsertNullifierInput;
3+
use light_compressed_account::{
4+
instruction_data::insert_into_queues::InsertNullifierInput, pubkey::Pubkey,
5+
};
46
use num_bigint::BigUint;
57

68
use crate::{
@@ -177,7 +179,9 @@ fn process_nullifiers_v1<'info>(
177179
// Discriminator is already checked in try_from_account_infos.
178180
let queue = bytemuck::from_bytes::<QueueAccount>(&queue_data[8..QueueAccount::LEN]);
179181
// 3. Check queue and Merkle tree are associated.
180-
if queue.metadata.associated_merkle_tree != (*merkle_pubkey).into() {
182+
if queue.metadata.associated_merkle_tree
183+
!= <anchor_lang::prelude::Pubkey as Into<Pubkey>>::into(*merkle_pubkey)
184+
{
181185
msg!(
182186
"Queue account {:?} is not associated with Merkle tree {:?}",
183187
nullifier_queue.key(),

programs/registry/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ light-system-program = { workspace = true, features = ["cpi"] }
2828
solana-security-txt = "1.1.0"
2929
light-merkle-tree-metadata = { workspace = true }
3030
light-batched-merkle-tree = { workspace = true }
31+
light-compressed-account = { workspace = true }
3132
[target.'cfg(not(target_os = "solana"))'.dependencies]
3233
solana-sdk = { workspace = true }
3334

programs/registry/src/lib.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,11 @@ pub fn check_forester(
682682
return err!(RegistryError::InvalidNetworkFee);
683683
}
684684
Ok(())
685-
} else if metadata.access_metadata.forester == authority.into() {
685+
} else if metadata.access_metadata.forester
686+
== <anchor_lang::prelude::Pubkey as Into<light_compressed_account::pubkey::Pubkey>>::into(
687+
authority,
688+
)
689+
{
686690
Ok(())
687691
} else {
688692
err!(RegistryError::InvalidSigner)

sdk-libs/program-test/src/indexer/utils.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ pub async fn assert_address_merkle_tree_initialized<R: RpcConnection>(
182182

183183
assert_eq!(
184184
merkle_tree_account.metadata.next_merkle_tree,
185-
Pubkey::default().into()
185+
light_compressed_account::pubkey::Pubkey::default()
186186
);
187187
let expected_access_meta_data = AccessMetadata {
188188
owner: (*owner_pubkey).into(),
@@ -195,7 +195,9 @@ pub async fn assert_address_merkle_tree_initialized<R: RpcConnection>(
195195
);
196196
assert_eq!(
197197
merkle_tree_account.metadata.associated_queue,
198-
(*queue_pubkey).into()
198+
<anchor_lang::prelude::Pubkey as Into<light_compressed_account::pubkey::Pubkey>>::into(
199+
*queue_pubkey,
200+
)
199201
);
200202

201203
let merkle_tree = get_indexed_merkle_tree::<

sdk-libs/sdk/src/transfer.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,16 @@ mod tests {
4848
LightAccountInfo {
4949
input: Some(LightInputAccountInfo {
5050
lamports,
51-
5251
// None of the following values matter.
5352
address: Some([1; 32]),
54-
data_hash: Some([0; 32]),
53+
data_hash: [0; 32],
5554
merkle_context: PackedMerkleContext {
5655
merkle_tree_pubkey_index: 0,
5756
nullifier_queue_pubkey_index: 0,
5857
leaf_index: 0,
5958
prove_by_index: false,
6059
},
61-
root_index: 0,
60+
root_index: Some(0),
6261
}),
6362
owner,
6463
// None of the following values matter.

0 commit comments

Comments
 (0)