Skip to content

Commit 3f14b16

Browse files
committed
test: mint
1 parent 33e0fe5 commit 3f14b16

File tree

5 files changed

+769
-427
lines changed

5 files changed

+769
-427
lines changed

program-libs/ctoken-types/src/state/mint.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use light_compressed_account::Pubkey;
22
use light_hasher::{errors::HasherError, sha256::Sha256BE, Hasher, Poseidon};
33
use light_zero_copy::{traits::ZeroCopyAt, ZeroCopy, ZeroCopyMut};
4+
use solana_msg::msg;
45
use zerocopy::IntoBytes;
56

67
use crate::{
@@ -124,8 +125,20 @@ where
124125

125126
// 5. Handle extensions if present
126127
if let Some(extensions) = extensions {
127-
let mut extension_hashchain = [0u8; 32];
128-
for extension in extensions {
128+
let mut extension_hashchain = if let Some(first_extension) = extensions.first() {
129+
if version == 0 {
130+
first_extension.hash_with_hasher::<Poseidon>(&hashed_spl_mint, hash_cache)
131+
} else if version == 1 {
132+
first_extension.hash_with_hasher::<Sha256BE>(&hashed_spl_mint, hash_cache)
133+
} else {
134+
Err(CTokenError::InvalidTokenDataVersion.into())
135+
}?
136+
} else {
137+
msg!("empty extensions");
138+
return Err(CTokenError::InvalidTokenDataVersion.into());
139+
};
140+
141+
for extension in extensions.iter().skip(1) {
129142
let extension_hash = if version == 0 {
130143
extension.hash_with_hasher::<Poseidon>(&hashed_spl_mint, hash_cache)
131144
} else if version == 1 {
@@ -181,7 +194,7 @@ impl CompressedMint {
181194
version: u8,
182195
) -> Result<[u8; 32], CTokenError> {
183196
if version == 0 {
184-
Ok(CompressedMint::hash_with_hashed_values_inner::<Poseidon>(
197+
Ok(CompressedMint::hash_with_hashed_values_generic::<Poseidon>(
185198
hashed_spl_mint,
186199
supply_bytes,
187200
decimals,
@@ -191,7 +204,7 @@ impl CompressedMint {
191204
version,
192205
)?)
193206
} else if version == 1 {
194-
Ok(CompressedMint::hash_with_hashed_values_inner::<Sha256BE>(
207+
Ok(CompressedMint::hash_with_hashed_values_generic::<Sha256BE>(
195208
hashed_spl_mint,
196209
supply_bytes,
197210
decimals,
@@ -204,7 +217,8 @@ impl CompressedMint {
204217
Err(CTokenError::InvalidTokenDataVersion)
205218
}
206219
}
207-
fn hash_with_hashed_values_inner<H: Hasher>(
220+
221+
fn hash_with_hashed_values_generic<H: Hasher>(
208222
hashed_spl_mint: &[u8; 32],
209223
supply_bytes: &[u8; 32],
210224
decimals: u8,

0 commit comments

Comments
 (0)