lib.rs 1.0 KB

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