solana_sdk/
system_transaction.rs1#![cfg(feature = "full")]
3
4use crate::{
5 hash::Hash,
6 message::Message,
7 pubkey::Pubkey,
8 signature::{Keypair, Signer},
9 system_instruction,
10 transaction::Transaction,
11};
12
13pub fn create_account(
15 from_keypair: &Keypair,
16 to_keypair: &Keypair,
17 recent_blockhash: Hash,
18 lamports: u64,
19 space: u64,
20 program_id: &Pubkey,
21) -> Transaction {
22 let from_pubkey = from_keypair.pubkey();
23 let to_pubkey = to_keypair.pubkey();
24 let instruction =
25 system_instruction::create_account(&from_pubkey, &to_pubkey, lamports, space, program_id);
26 let message = Message::new(&[instruction], Some(&from_pubkey));
27 Transaction::new(&[from_keypair, to_keypair], message, recent_blockhash)
28}
29
30pub fn allocate(
32 payer_keypair: &Keypair,
33 account_keypair: &Keypair,
34 recent_blockhash: Hash,
35 space: u64,
36) -> Transaction {
37 let payer_pubkey = payer_keypair.pubkey();
38 let account_pubkey = account_keypair.pubkey();
39 let instruction = system_instruction::allocate(&account_pubkey, space);
40 let message = Message::new(&[instruction], Some(&payer_pubkey));
41 Transaction::new(&[payer_keypair, account_keypair], message, recent_blockhash)
42}
43
44pub fn assign(from_keypair: &Keypair, recent_blockhash: Hash, program_id: &Pubkey) -> Transaction {
46 let from_pubkey = from_keypair.pubkey();
47 let instruction = system_instruction::assign(&from_pubkey, program_id);
48 let message = Message::new(&[instruction], Some(&from_pubkey));
49 Transaction::new(&[from_keypair], message, recent_blockhash)
50}
51
52pub fn transfer(
54 from_keypair: &Keypair,
55 to: &Pubkey,
56 lamports: u64,
57 recent_blockhash: Hash,
58) -> Transaction {
59 let from_pubkey = from_keypair.pubkey();
60 let instruction = system_instruction::transfer(&from_pubkey, to, lamports);
61 let message = Message::new(&[instruction], Some(&from_pubkey));
62 Transaction::new(&[from_keypair], message, recent_blockhash)
63}
64
65pub fn nonced_transfer(
67 from_keypair: &Keypair,
68 to: &Pubkey,
69 lamports: u64,
70 nonce_account: &Pubkey,
71 nonce_authority: &Keypair,
72 nonce_hash: Hash,
73) -> Transaction {
74 let from_pubkey = from_keypair.pubkey();
75 let instruction = system_instruction::transfer(&from_pubkey, to, lamports);
76 let message = Message::new_with_nonce(
77 vec![instruction],
78 Some(&from_pubkey),
79 nonce_account,
80 &nonce_authority.pubkey(),
81 );
82 Transaction::new(&[from_keypair, nonce_authority], message, nonce_hash)
83}