processor.rs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. use {
  2. borsh::BorshDeserialize,
  3. solana_program::{
  4. account_info::AccountInfo,
  5. entrypoint::ProgramResult,
  6. program_error::ProgramError,
  7. pubkey::Pubkey,
  8. },
  9. };
  10. use crate::instructions::{ create_token_mint, mint_to_wallet, transfer_to_wallet };
  11. use crate::state::mint_state::{ TokenMetadata, MintTokensTo, TransferTokensTo };
  12. pub fn process_instruction(
  13. program_id: &Pubkey,
  14. accounts: &[AccountInfo],
  15. instruction_data: &[u8],
  16. ) -> ProgramResult {
  17. match TokenMetadata::try_from_slice(instruction_data) {
  18. Ok(token_metadata_instruction) => return create_token_mint::create_token_mint(
  19. program_id,
  20. accounts,
  21. token_metadata_instruction.title,
  22. token_metadata_instruction.symbol,
  23. token_metadata_instruction.uri,
  24. token_metadata_instruction.mint_authority_pda_bump,
  25. ),
  26. Err(_) => {},
  27. };
  28. match MintTokensTo::try_from_slice(instruction_data) {
  29. Ok(mint_to_wallet_instruction) => return mint_to_wallet::mint_to_wallet(
  30. program_id,
  31. accounts,
  32. mint_to_wallet_instruction.amount,
  33. mint_to_wallet_instruction.mint_authority_pda_bump,
  34. ),
  35. Err(_) => {},
  36. };
  37. match TransferTokensTo::try_from_slice(instruction_data) {
  38. Ok(transfer_to_wallet_instruction) => return transfer_to_wallet::transfer_to_wallet(
  39. program_id,
  40. accounts,
  41. transfer_to_wallet_instruction.amount,
  42. ),
  43. Err(_) => {},
  44. };
  45. Err(ProgramError::InvalidInstructionData)
  46. }