initialize.rs 781 B

12345678910111213141516171819202122232425262728
  1. use realloc_api::prelude::*;
  2. use steel::*;
  3. pub fn process_initialize(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult {
  4. // Load accounts.
  5. let [signer_info, counter_info, system_program] = accounts else {
  6. return Err(ProgramError::NotEnoughAccountKeys);
  7. };
  8. signer_info.is_signer()?;
  9. counter_info.is_empty()?.is_writable()?.has_seeds(
  10. &[COUNTER],
  11. &realloc_api::ID
  12. )?;
  13. system_program.is_program(&system_program::ID)?;
  14. // Initialize counter.
  15. create_account::<Counter>(
  16. counter_info,
  17. system_program,
  18. signer_info,
  19. &realloc_api::ID,
  20. &[COUNTER],
  21. )?;
  22. let counter = counter_info.as_account_mut::<Counter>(&realloc_api::ID)?;
  23. counter.value = 0;
  24. Ok(())
  25. }