lib.rs 1.1 KB

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