lib.rs 910 B

1234567891011121314151617181920212223242526272829303132
  1. use borsh::{BorshDeserialize, BorshSerialize};
  2. use solana_program::{
  3. account_info::AccountInfo, entrypoint, entrypoint::ProgramResult, msg, pubkey::Pubkey,
  4. };
  5. entrypoint!(process_instruction);
  6. fn process_instruction(
  7. _program_id: &Pubkey,
  8. _accounts: &[AccountInfo],
  9. instruction_data: &[u8],
  10. ) -> ProgramResult {
  11. // Attempt to serialize the BPF format to our struct
  12. // using Borsh
  13. //
  14. let instruction_data_object = InstructionData::try_from_slice(instruction_data)?;
  15. msg!("Welcome to the park, {}!", instruction_data_object.name);
  16. if instruction_data_object.height > 5 {
  17. msg!("You are tall enough to ride this ride. Congratulations.");
  18. } else {
  19. msg!("You are NOT tall enough to ride this ride. Sorry mate.");
  20. };
  21. Ok(())
  22. }
  23. #[derive(BorshSerialize, BorshDeserialize, Debug)]
  24. pub struct InstructionData {
  25. name: String,
  26. height: u32,
  27. }