lib.rs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. use borsh::BorshDeserialize;
  2. use lever::SetPowerStatus;
  3. use solana_program::{
  4. account_info::{
  5. next_account_info, AccountInfo
  6. },
  7. entrypoint,
  8. entrypoint::ProgramResult,
  9. instruction::{ AccountMeta, Instruction },
  10. pubkey::Pubkey,
  11. program::invoke,
  12. };
  13. entrypoint!(pull_lever);
  14. fn pull_lever(
  15. _program_id: &Pubkey,
  16. accounts: &[AccountInfo],
  17. instruction_data: &[u8],
  18. ) -> ProgramResult {
  19. let accounts_iter = &mut accounts.iter();
  20. let power = next_account_info(accounts_iter)?;
  21. let lever_program = next_account_info(accounts_iter)?;
  22. let set_power_status_instruction = SetPowerStatus::try_from_slice(instruction_data)?;
  23. let ix = Instruction::new_with_borsh(
  24. lever_program.key.clone(), // Our lever program's ID
  25. &set_power_status_instruction, // Passing instructions through
  26. vec![AccountMeta::new(power.key.clone(), false)], // Just the required account for the other program
  27. );
  28. invoke(&ix, &[power.clone()])
  29. }