processor.rs 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. use {
  2. borsh::{BorshDeserialize, BorshSerialize},
  3. solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, pubkey::Pubkey},
  4. };
  5. use crate::instructions::{
  6. create::{create_token, CreateTokenArgs},
  7. mint_nft::mint_nft,
  8. mint_spl::{mint_spl, MintSplArgs},
  9. transfer::{transfer_tokens, TransferTokensArgs},
  10. };
  11. #[derive(BorshSerialize, BorshDeserialize, Debug)]
  12. enum MyInstruction {
  13. Create(CreateTokenArgs),
  14. MintNft,
  15. MintSpl(MintSplArgs),
  16. TransferTokens(TransferTokensArgs),
  17. }
  18. pub fn process_instruction(
  19. _program_id: &Pubkey,
  20. accounts: &[AccountInfo],
  21. instruction_data: &[u8],
  22. ) -> ProgramResult {
  23. let instruction = MyInstruction::try_from_slice(instruction_data)?;
  24. match instruction {
  25. MyInstruction::Create(args) => create_token(accounts, args),
  26. MyInstruction::MintNft => mint_nft(accounts),
  27. MyInstruction::MintSpl(args) => mint_spl(accounts, args),
  28. MyInstruction::TransferTokens(args) => transfer_tokens(accounts, args),
  29. }
  30. }