solana/sdk/src/system_transaction.rs

77 lines
2.5 KiB
Rust
Raw Normal View History

//! 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};
2018-12-14 20:39:10 -08:00
use crate::system_instruction::SystemInstruction;
use crate::system_program;
2019-03-21 10:03:50 -06:00
use crate::transaction::Transaction;
2018-11-16 08:04:46 -08:00
pub struct SystemTransaction {}
impl SystemTransaction {
2018-11-16 08:04:46 -08:00
/// Create and sign new SystemInstruction::CreateAccount transaction
pub fn new_account(
from_keypair: &Keypair,
to: &Pubkey,
2019-03-02 10:25:16 -08:00
recent_blockhash: Hash,
2019-03-05 16:28:14 -08:00
lamports: u64,
space: u64,
program_id: &Pubkey,
_fee: u64,
) -> Transaction {
2019-03-21 10:03:50 -06:00
let from_pubkey = from_keypair.pubkey();
let create_instruction =
SystemInstruction::new_account(&from_pubkey, to, lamports, space, program_id);
2019-03-21 10:03:50 -06:00
let instructions = vec![create_instruction];
Transaction::new_signed_instructions(&[from_keypair], instructions, recent_blockhash)
}
/// Create and sign a transaction to create a system account
pub fn new_user_account(
from_keypair: &Keypair,
to: &Pubkey,
2019-03-05 16:28:14 -08:00
lamports: u64,
2019-03-02 10:25:16 -08:00
recent_blockhash: Hash,
fee: u64,
) -> Transaction {
let program_id = system_program::id();
Self::new_account(
2019-03-02 10:20:10 -08:00
from_keypair,
to,
2019-03-02 10:25:16 -08:00
recent_blockhash,
2019-03-05 16:28:14 -08:00
lamports,
2019-03-02 10:20:10 -08:00
0,
&program_id,
2019-03-02 10:20:10 -08:00
fee,
)
}
2019-03-21 10:03:50 -06:00
2018-11-16 08:04:46 -08:00
/// Create and sign new SystemInstruction::Assign transaction
pub fn new_assign(
from_keypair: &Keypair,
2019-03-02 10:25:16 -08:00
recent_blockhash: Hash,
program_id: &Pubkey,
_fee: u64,
) -> Transaction {
2019-03-21 10:03:50 -06:00
let from_pubkey = from_keypair.pubkey();
let assign_instruction = SystemInstruction::new_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
/// Create and sign new SystemInstruction::Transfer transaction
pub fn new_transfer(
from_keypair: &Keypair,
to: &Pubkey,
2019-03-05 16:28:14 -08:00
lamports: u64,
2019-03-02 10:25:16 -08:00
recent_blockhash: Hash,
_fee: u64,
) -> Transaction {
2019-03-21 10:03:50 -06:00
let from_pubkey = from_keypair.pubkey();
let move_instruction = SystemInstruction::new_transfer(&from_pubkey, to, lamports);
2019-03-21 10:03:50 -06:00
let instructions = vec![move_instruction];
Transaction::new_signed_instructions(&[from_keypair], instructions, recent_blockhash)
}
}