processor.rs 814 B

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