| 
									
										
										
										
											2018-09-26 10:07:53 -06:00
										 |  |  | //! The `system_transaction` module provides functionality for creating system transactions.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-14 20:39:10 -08:00
										 |  |  | use crate::hash::Hash;
 | 
					
						
							|  |  |  | use crate::pubkey::Pubkey;
 | 
					
						
							| 
									
										
										
										
											2019-03-21 10:03:50 -06:00
										 |  |  | use crate::signature::{Keypair, KeypairUtil};
 | 
					
						
							| 
									
										
										
										
											2019-04-03 09:45:57 -06:00
										 |  |  | use crate::system_instruction;
 | 
					
						
							| 
									
										
										
										
											2018-12-14 20:39:10 -08:00
										 |  |  | use crate::system_program;
 | 
					
						
							| 
									
										
										
										
											2019-03-21 10:03:50 -06:00
										 |  |  | use crate::transaction::Transaction;
 | 
					
						
							| 
									
										
										
										
											2018-11-16 08:04:46 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-03 09:45:57 -06:00
										 |  |  | /// Create and sign new SystemInstruction::CreateAccount transaction
 | 
					
						
							|  |  |  | pub fn create_account(
 | 
					
						
							|  |  |  |     from_keypair: &Keypair,
 | 
					
						
							|  |  |  |     to: &Pubkey,
 | 
					
						
							|  |  |  |     recent_blockhash: Hash,
 | 
					
						
							|  |  |  |     lamports: u64,
 | 
					
						
							|  |  |  |     space: u64,
 | 
					
						
							|  |  |  |     program_id: &Pubkey,
 | 
					
						
							|  |  |  | ) -> Transaction {
 | 
					
						
							|  |  |  |     let from_pubkey = from_keypair.pubkey();
 | 
					
						
							|  |  |  |     let create_instruction =
 | 
					
						
							|  |  |  |         system_instruction::create_account(&from_pubkey, to, lamports, space, program_id);
 | 
					
						
							|  |  |  |     let instructions = vec![create_instruction];
 | 
					
						
							|  |  |  |     Transaction::new_signed_instructions(&[from_keypair], instructions, recent_blockhash)
 | 
					
						
							|  |  |  | }
 | 
					
						
							| 
									
										
										
										
											2019-02-01 08:36:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-03 09:45:57 -06:00
										 |  |  | /// Create and sign a transaction to create a system account
 | 
					
						
							|  |  |  | pub fn create_user_account(
 | 
					
						
							|  |  |  |     from_keypair: &Keypair,
 | 
					
						
							|  |  |  |     to: &Pubkey,
 | 
					
						
							|  |  |  |     lamports: u64,
 | 
					
						
							|  |  |  |     recent_blockhash: Hash,
 | 
					
						
							|  |  |  | ) -> Transaction {
 | 
					
						
							|  |  |  |     let program_id = system_program::id();
 | 
					
						
							| 
									
										
										
										
											2019-05-20 10:03:19 -07:00
										 |  |  |     create_account(from_keypair, to, recent_blockhash, lamports, 0, &program_id)
 | 
					
						
							| 
									
										
										
										
											2019-04-03 09:45:57 -06:00
										 |  |  | }
 | 
					
						
							| 
									
										
										
										
											2019-03-21 10:03:50 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-03 09:45:57 -06:00
										 |  |  | /// Create and sign new system_instruction::Assign transaction
 | 
					
						
							| 
									
										
										
										
											2019-05-20 10:03:19 -07:00
										 |  |  | pub fn assign(from_keypair: &Keypair, recent_blockhash: Hash, program_id: &Pubkey) -> Transaction {
 | 
					
						
							| 
									
										
										
										
											2019-04-03 09:45:57 -06:00
										 |  |  |     let from_pubkey = from_keypair.pubkey();
 | 
					
						
							|  |  |  |     let assign_instruction = system_instruction::assign(&from_pubkey, program_id);
 | 
					
						
							|  |  |  |     let instructions = vec![assign_instruction];
 | 
					
						
							|  |  |  |     Transaction::new_signed_instructions(&[from_keypair], instructions, recent_blockhash)
 | 
					
						
							|  |  |  | }
 | 
					
						
							| 
									
										
										
										
											2019-03-21 10:03:50 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-03 09:45:57 -06:00
										 |  |  | /// Create and sign new system_instruction::Transfer transaction
 | 
					
						
							|  |  |  | pub fn transfer(
 | 
					
						
							|  |  |  |     from_keypair: &Keypair,
 | 
					
						
							|  |  |  |     to: &Pubkey,
 | 
					
						
							|  |  |  |     lamports: u64,
 | 
					
						
							|  |  |  |     recent_blockhash: Hash,
 | 
					
						
							|  |  |  | ) -> Transaction {
 | 
					
						
							|  |  |  |     let from_pubkey = from_keypair.pubkey();
 | 
					
						
							| 
									
										
										
										
											2019-04-23 13:30:42 -06:00
										 |  |  |     let transfer_instruction = system_instruction::transfer(&from_pubkey, to, lamports);
 | 
					
						
							|  |  |  |     let instructions = vec![transfer_instruction];
 | 
					
						
							| 
									
										
										
										
											2019-04-03 09:45:57 -06:00
										 |  |  |     Transaction::new_signed_instructions(&[from_keypair], instructions, recent_blockhash)
 | 
					
						
							| 
									
										
										
										
											2018-09-26 10:07:53 -06:00
										 |  |  | }
 |