mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-16 15:10:20 +00:00
Discriminator
This commit is contained in:
10
src/utils.rs
10
src/utils.rs
@@ -50,14 +50,20 @@ macro_rules! impl_account_from_bytes {
|
||||
pub fn try_from_bytes(
|
||||
data: &[u8],
|
||||
) -> Result<&Self, solana_program::program_error::ProgramError> {
|
||||
bytemuck::try_from_bytes::<Self>(data).or(Err(
|
||||
if (Self::discriminator() as u8).ne(&data[0]) {
|
||||
return Err(solana_program::program_error::ProgramError::InvalidAccountData);
|
||||
}
|
||||
bytemuck::try_from_bytes::<Self>(&data[8..]).or(Err(
|
||||
solana_program::program_error::ProgramError::InvalidAccountData,
|
||||
))
|
||||
}
|
||||
pub fn try_from_bytes_mut(
|
||||
data: &mut [u8],
|
||||
) -> Result<&mut Self, solana_program::program_error::ProgramError> {
|
||||
bytemuck::try_from_bytes_mut::<Self>(data).or(Err(
|
||||
if (Self::discriminator() as u8).ne(&data[0]) {
|
||||
return Err(solana_program::program_error::ProgramError::InvalidAccountData);
|
||||
}
|
||||
bytemuck::try_from_bytes_mut::<Self>(&mut data[8..]).or(Err(
|
||||
solana_program::program_error::ProgramError::InvalidAccountData,
|
||||
))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user