mint_to_checked.rs 797 B

1234567891011121314151617181920212223
  1. use pinocchio::{account_info::AccountInfo, program_error::ProgramError, ProgramResult};
  2. use super::shared;
  3. #[inline(always)]
  4. pub fn process_mint_to_checked(accounts: &[AccountInfo], instruction_data: &[u8]) -> ProgramResult {
  5. // expected u64 (8) + u8 (1)
  6. let (amount, decimals) = if instruction_data.len() == 9 {
  7. let (amount, decimals) = instruction_data.split_at(core::mem::size_of::<u64>());
  8. (
  9. u64::from_le_bytes(
  10. amount
  11. .try_into()
  12. .map_err(|_error| ProgramError::InvalidInstructionData)?,
  13. ),
  14. decimals.first(),
  15. )
  16. } else {
  17. return Err(ProgramError::InvalidInstructionData);
  18. };
  19. shared::mint_to::process_mint_to(accounts, amount, decimals.copied())
  20. }