sdk.rs 936 B

12345678910111213141516171819202122232425262728293031
  1. use steel::*;
  2. use crate::prelude::*;
  3. /// Create an PDA and store a String in it
  4. pub fn create_account(signer: Pubkey, user: CreateAccount) -> Instruction {
  5. Instruction {
  6. program_id: crate::ID,
  7. accounts: vec![
  8. AccountMeta::new(signer, true),
  9. AccountMeta::new(User::pda(signer).0, false),
  10. AccountMeta::new_readonly(system_program::ID, false),
  11. ],
  12. data: user.to_bytes(),
  13. }
  14. }
  15. /// Creates an instruction to close the account,
  16. /// in our case the PDA. The PDA address is derived from
  17. /// the `payer` public key
  18. pub fn close_account(signer: Pubkey) -> Instruction {
  19. Instruction {
  20. program_id: crate::ID,
  21. accounts: vec![
  22. AccountMeta::new(signer, true),
  23. AccountMeta::new(User::pda(signer).0, false),
  24. AccountMeta::new_readonly(system_program::ID, false),
  25. ],
  26. data: CloseAccount.to_bytes(),
  27. }
  28. }