2018-09-26 09:07:53 -07:00
|
|
|
//! The `system_transaction` module provides functionality for creating system transactions.
|
2020-10-24 08:39:28 -07:00
|
|
|
#![cfg(feature = "full")]
|
2018-09-26 09:07:53 -07:00
|
|
|
|
2019-10-19 18:23:27 -07:00
|
|
|
use crate::{
|
|
|
|
hash::Hash,
|
2020-06-24 13:52:38 -07:00
|
|
|
message::Message,
|
2019-10-19 18:23:27 -07:00
|
|
|
pubkey::Pubkey,
|
2020-02-20 13:28:55 -08:00
|
|
|
signature::{Keypair, Signer},
|
2019-10-19 18:23:27 -07:00
|
|
|
system_instruction,
|
|
|
|
transaction::Transaction,
|
|
|
|
};
|
2018-11-16 08:04:46 -08:00
|
|
|
|
2019-04-03 08:45:57 -07:00
|
|
|
/// Create and sign new SystemInstruction::CreateAccount transaction
|
|
|
|
pub fn create_account(
|
|
|
|
from_keypair: &Keypair,
|
2019-11-08 02:27:35 -08:00
|
|
|
to_keypair: &Keypair,
|
2019-04-03 08:45:57 -07:00
|
|
|
recent_blockhash: Hash,
|
|
|
|
lamports: u64,
|
|
|
|
space: u64,
|
|
|
|
program_id: &Pubkey,
|
|
|
|
) -> Transaction {
|
|
|
|
let from_pubkey = from_keypair.pubkey();
|
2019-11-08 02:27:35 -08:00
|
|
|
let to_pubkey = to_keypair.pubkey();
|
2020-06-24 13:52:38 -07:00
|
|
|
let instruction =
|
2019-11-08 02:27:35 -08:00
|
|
|
system_instruction::create_account(&from_pubkey, &to_pubkey, lamports, space, program_id);
|
2020-06-24 13:52:38 -07:00
|
|
|
let message = Message::new(&[instruction], Some(&from_pubkey));
|
|
|
|
Transaction::new(&[from_keypair, to_keypair], message, recent_blockhash)
|
2019-04-03 08:45:57 -07:00
|
|
|
}
|
2019-02-01 07:36:35 -08:00
|
|
|
|
2019-04-03 08:45:57 -07: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 08:45:57 -07:00
|
|
|
let from_pubkey = from_keypair.pubkey();
|
2020-06-24 13:52:38 -07:00
|
|
|
let instruction = system_instruction::assign(&from_pubkey, program_id);
|
|
|
|
let message = Message::new(&[instruction], Some(&from_pubkey));
|
|
|
|
Transaction::new(&[from_keypair], message, recent_blockhash)
|
2019-04-03 08:45:57 -07:00
|
|
|
}
|
2019-03-21 09:03:50 -07:00
|
|
|
|
2019-04-03 08:45:57 -07: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();
|
2020-06-24 13:52:38 -07:00
|
|
|
let instruction = system_instruction::transfer(&from_pubkey, to, lamports);
|
|
|
|
let message = Message::new(&[instruction], Some(&from_pubkey));
|
|
|
|
Transaction::new(&[from_keypair], message, recent_blockhash)
|
2018-09-26 09:07:53 -07:00
|
|
|
}
|
2019-12-27 12:35:49 -08:00
|
|
|
|
|
|
|
/// Create and sign new nonced system_instruction::Transfer transaction
|
|
|
|
pub fn nonced_transfer(
|
|
|
|
from_keypair: &Keypair,
|
|
|
|
to: &Pubkey,
|
|
|
|
lamports: u64,
|
|
|
|
nonce_account: &Pubkey,
|
|
|
|
nonce_authority: &Keypair,
|
|
|
|
nonce_hash: Hash,
|
|
|
|
) -> Transaction {
|
|
|
|
let from_pubkey = from_keypair.pubkey();
|
2020-06-24 13:52:38 -07:00
|
|
|
let instruction = system_instruction::transfer(&from_pubkey, to, lamports);
|
|
|
|
let message = Message::new_with_nonce(
|
|
|
|
vec![instruction],
|
2019-12-27 12:35:49 -08:00
|
|
|
Some(&from_pubkey),
|
|
|
|
nonce_account,
|
|
|
|
&nonce_authority.pubkey(),
|
2020-06-24 13:52:38 -07:00
|
|
|
);
|
|
|
|
Transaction::new(&[from_keypair, nonce_authority], message, nonce_hash)
|
2019-12-27 12:35:49 -08:00
|
|
|
}
|