get_on_ride.rs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. use solana_program::{
  2. entrypoint::ProgramResult,
  3. msg,
  4. program_error::ProgramError,
  5. };
  6. use crate::state::ride;
  7. // InstructionData Data
  8. pub struct GetOnRideInstructionData {
  9. pub rider_name: String,
  10. pub rider_height: u32,
  11. pub rider_ticket_count: u32,
  12. pub ride: String,
  13. }
  14. pub fn get_on_ride(ix: GetOnRideInstructionData) -> ProgramResult {
  15. let rides_list = ride::get_rides();
  16. for ride in rides_list.iter() {
  17. if ix.ride.eq(&ride.name) {
  18. msg!("You're about to ride the {}!", ride.name);
  19. if ix.rider_ticket_count < ride.tickets {
  20. msg!(" Sorry {}, you need {} tickets to ride the {}!", ix.rider_name, ride.tickets, ride.name);
  21. return Ok(())
  22. };
  23. if ix.rider_height < ride.min_height {
  24. msg!(" Sorry {}, you need to be {}\" tall to ride the {}!", ix.rider_name, ride.min_height, ride.name);
  25. return Ok(())
  26. };
  27. msg!(" Welcome aboard the {}!", ride.name);
  28. if ride.upside_down {
  29. msg!(" Btw, this ride goes upside down. Hold on tight!");
  30. };
  31. return Ok(())
  32. }
  33. }
  34. Err(ProgramError::InvalidInstructionData)
  35. }