lib.rs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. use solana_program::{
  2. account_info::{next_account_info, AccountInfo},
  3. entrypoint,
  4. entrypoint::ProgramResult,
  5. msg,
  6. native_token::LAMPORTS_PER_SOL,
  7. program::invoke,
  8. pubkey::Pubkey,
  9. system_instruction, system_program,
  10. };
  11. entrypoint!(process_instruction);
  12. fn process_instruction(
  13. _program_id: &Pubkey,
  14. accounts: &[AccountInfo],
  15. _instruction_data: &[u8],
  16. ) -> ProgramResult {
  17. let accounts_iter = &mut accounts.iter();
  18. let payer = next_account_info(accounts_iter)?;
  19. let new_account = next_account_info(accounts_iter)?;
  20. let system_program = next_account_info(accounts_iter)?;
  21. msg!("Program invoked. Creating a system account...");
  22. msg!(" New public key will be: {}", &new_account.key.to_string());
  23. invoke(
  24. &system_instruction::create_account(
  25. payer.key,
  26. new_account.key,
  27. LAMPORTS_PER_SOL,
  28. 0,
  29. &system_program::ID,
  30. ),
  31. &[payer.clone(), new_account.clone(), system_program.clone()],
  32. )?;
  33. msg!("Account created succesfully.");
  34. Ok(())
  35. }