lib.rs 986 B

1234567891011121314151617181920212223242526272829303132333435
  1. #![allow(clippy::result_large_err)]
  2. use anchor_lang::prelude::*;
  3. use lever::cpi::accounts::SetPowerStatus;
  4. use lever::program::Lever;
  5. use lever::{self, PowerStatus};
  6. declare_id!("EJfTLXDCJTVwBgGpz9X2Me4CWHbvg8F8zsM7fiVJLLeR");
  7. #[program]
  8. mod hand {
  9. use super::*;
  10. pub fn pull_lever(ctx: Context<PullLever>, name: String) -> anchor_lang::Result<()> {
  11. // Hitting the switch_power method on the lever program
  12. //
  13. lever::cpi::switch_power(
  14. CpiContext::new(
  15. ctx.accounts.lever_program.to_account_info(),
  16. // Using the accounts context struct from the lever program
  17. //
  18. SetPowerStatus {
  19. power: ctx.accounts.power.to_account_info(),
  20. },
  21. ),
  22. name,
  23. )
  24. }
  25. }
  26. #[derive(Accounts)]
  27. pub struct PullLever<'info> {
  28. #[account(mut)]
  29. pub power: Account<'info, PowerStatus>,
  30. pub lever_program: Program<'info, Lever>,
  31. }