approve_checked.rs 791 B

12345678910111213141516171819202122
  1. use {
  2. super::{shared, U64_BYTES},
  3. pinocchio::{account_info::AccountInfo, ProgramResult},
  4. spl_token_interface::error::TokenError,
  5. };
  6. #[inline(always)]
  7. pub fn process_approve_checked(accounts: &[AccountInfo], instruction_data: &[u8]) -> ProgramResult {
  8. // expected u64 (8) + u8 (1)
  9. let (amount, decimals) = if instruction_data.len() >= 9 {
  10. let (amount, decimals) = instruction_data.split_at(U64_BYTES);
  11. (
  12. // SAFETY: The size of `amount` is `U64_BYTES` bytes.
  13. unsafe { u64::from_le_bytes(*(amount.as_ptr() as *const [u8; U64_BYTES])) },
  14. decimals.first().copied(),
  15. )
  16. } else {
  17. return Err(TokenError::InvalidInstruction.into());
  18. };
  19. shared::approve::process_approve(accounts, amount, decimals)
  20. }