Last active
August 1, 2025 16:39
-
-
Save Taylor123/9334584b184db82bf0fbcffe978eb60b to your computer and use it in GitHub Desktop.
Pinocchio Get Extension Types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Modified from unused Pinocchio T22 extension code | |
/// Iterate over all extension data and return the lists of extension types. | |
pub fn get_all_extensions_for_mint( | |
acc_data_bytes: &[u8], | |
) -> Result<Vec<ExtensionType>, ProgramError> { | |
let mut extension_types = Vec::new(); | |
let ext_bytes = &acc_data_bytes[pinocchio_token2022::state::Mint::BASE_LEN | |
+ EXTENSIONS_PADDING | |
+ EXTENSION_START_OFFSET..]; | |
let mut start = 0; | |
let end = ext_bytes.len(); | |
while start < end { | |
let ext_type_idx = start; | |
let ext_len_idx = ext_type_idx + 2; | |
let ext_type: [u8; 2] = ext_bytes[ext_type_idx..ext_type_idx + EXTENSION_TYPE_LEN] | |
.try_into() | |
.map_err(|_| ProgramError::InvalidAccountData)?; | |
let ext_type = | |
ExtensionType::from_bytes(ext_type).ok_or(ProgramError::InvalidAccountData)?; | |
let ext_len: [u8; 2] = ext_bytes[ext_len_idx..ext_len_idx + EXTENSION_LENGTH_LEN] | |
.try_into() | |
.map_err(|_| ProgramError::InvalidAccountData)?; | |
let ext_len = u16::from_le_bytes(ext_len); | |
extension_types.push(ext_type); | |
start = start + EXTENSION_TYPE_LEN + EXTENSION_LENGTH_LEN + ext_len as usize; | |
} | |
Ok(extension_types) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment