processor.rs 843 B

1234567891011121314151617181920212223242526272829303132
  1. use borsh::{ BorshDeserialize, BorshSerialize };
  2. use solana_program::{
  3. account_info::AccountInfo,
  4. entrypoint::ProgramResult,
  5. pubkey::Pubkey,
  6. };
  7. use crate::instruction::transfer_sol_with_cpi;
  8. use crate::instruction::transfer_sol_with_program;
  9. #[derive(BorshSerialize, BorshDeserialize, Debug)]
  10. pub enum TransferInstruction {
  11. CpiTransfer(u64),
  12. ProgramTransfer(u64),
  13. }
  14. pub fn process_instruction(
  15. program_id: &Pubkey,
  16. accounts: &[AccountInfo],
  17. input: &[u8],
  18. ) -> ProgramResult {
  19. let instruction = TransferInstruction::try_from_slice(&input)?;
  20. match instruction {
  21. TransferInstruction::CpiTransfer(
  22. args) => transfer_sol_with_cpi(accounts, args),
  23. TransferInstruction::ProgramTransfer(
  24. args) => transfer_sol_with_program(program_id, accounts, args),
  25. }
  26. }