clone_solana_system_transaction/
lib.rs

1//! The `system_transaction` module provides functionality for creating system transactions.
2
3use {
4    clone_solana_hash::Hash, clone_solana_keypair::Keypair, clone_solana_message::Message,
5    clone_solana_pubkey::Pubkey, clone_solana_signer::Signer,
6    clone_solana_system_interface::instruction as system_instruction,
7    clone_solana_transaction::Transaction,
8};
9
10/// Create and sign new SystemInstruction::CreateAccount transaction
11pub fn create_account(
12    from_keypair: &Keypair,
13    to_keypair: &Keypair,
14    recent_blockhash: Hash,
15    lamports: u64,
16    space: u64,
17    program_id: &Pubkey,
18) -> Transaction {
19    let from_pubkey = from_keypair.pubkey();
20    let to_pubkey = to_keypair.pubkey();
21    let instruction =
22        system_instruction::create_account(&from_pubkey, &to_pubkey, lamports, space, program_id);
23    let message = Message::new(&[instruction], Some(&from_pubkey));
24    Transaction::new(&[from_keypair, to_keypair], message, recent_blockhash)
25}
26
27/// Create and sign new SystemInstruction::Allocate transaction
28pub fn allocate(
29    payer_keypair: &Keypair,
30    account_keypair: &Keypair,
31    recent_blockhash: Hash,
32    space: u64,
33) -> Transaction {
34    let payer_pubkey = payer_keypair.pubkey();
35    let account_pubkey = account_keypair.pubkey();
36    let instruction = system_instruction::allocate(&account_pubkey, space);
37    let message = Message::new(&[instruction], Some(&payer_pubkey));
38    Transaction::new(&[payer_keypair, account_keypair], message, recent_blockhash)
39}
40
41/// Create and sign new system_instruction::Assign transaction
42pub fn assign(from_keypair: &Keypair, recent_blockhash: Hash, program_id: &Pubkey) -> Transaction {
43    let from_pubkey = from_keypair.pubkey();
44    let instruction = system_instruction::assign(&from_pubkey, program_id);
45    let message = Message::new(&[instruction], Some(&from_pubkey));
46    Transaction::new(&[from_keypair], message, recent_blockhash)
47}
48
49/// Create and sign new system_instruction::Transfer transaction
50pub fn transfer(
51    from_keypair: &Keypair,
52    to: &Pubkey,
53    lamports: u64,
54    recent_blockhash: Hash,
55) -> Transaction {
56    let from_pubkey = from_keypair.pubkey();
57    let instruction = system_instruction::transfer(&from_pubkey, to, lamports);
58    let message = Message::new(&[instruction], Some(&from_pubkey));
59    Transaction::new(&[from_keypair], message, recent_blockhash)
60}
61
62/// Create and sign new nonced system_instruction::Transfer transaction
63pub fn nonced_transfer(
64    from_keypair: &Keypair,
65    to: &Pubkey,
66    lamports: u64,
67    nonce_account: &Pubkey,
68    nonce_authority: &Keypair,
69    nonce_hash: Hash,
70) -> Transaction {
71    let from_pubkey = from_keypair.pubkey();
72    let instruction = system_instruction::transfer(&from_pubkey, to, lamports);
73    let message = Message::new_with_nonce(
74        vec![instruction],
75        Some(&from_pubkey),
76        nonce_account,
77        &nonce_authority.pubkey(),
78    );
79    Transaction::new(&[from_keypair, nonce_authority], message, nonce_hash)
80}