2018-12-14 20:39:10 -08:00
|
|
|
use crate::pubkey::Pubkey;
|
2019-02-28 04:48:44 -07:00
|
|
|
use crate::system_program;
|
|
|
|
use crate::transaction_builder::BuilderInstruction;
|
2018-11-16 08:04:46 -08:00
|
|
|
|
2019-01-14 18:21:42 -07:00
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
2018-11-16 08:04:46 -08:00
|
|
|
pub enum SystemInstruction {
|
|
|
|
/// Create a new account
|
|
|
|
/// * Transaction::keys[0] - source
|
|
|
|
/// * Transaction::keys[1] - new account key
|
|
|
|
/// * tokens - number of tokens to transfer to the new account
|
|
|
|
/// * space - memory to allocate if greater then zero
|
|
|
|
/// * program_id - the program id of the new account
|
|
|
|
CreateAccount {
|
|
|
|
tokens: u64,
|
|
|
|
space: u64,
|
|
|
|
program_id: Pubkey,
|
|
|
|
},
|
|
|
|
/// Assign account to a program
|
|
|
|
/// * Transaction::keys[0] - account to assign
|
|
|
|
Assign { program_id: Pubkey },
|
|
|
|
/// Move tokens
|
|
|
|
/// * Transaction::keys[0] - source
|
|
|
|
/// * Transaction::keys[1] - destination
|
|
|
|
Move { tokens: u64 },
|
|
|
|
}
|
2019-02-28 04:48:44 -07:00
|
|
|
|
|
|
|
impl SystemInstruction {
|
2019-03-03 15:43:51 -07:00
|
|
|
pub fn new_program_account(
|
|
|
|
from_id: Pubkey,
|
|
|
|
to_id: Pubkey,
|
|
|
|
tokens: u64,
|
|
|
|
space: u64,
|
|
|
|
program_id: Pubkey,
|
|
|
|
) -> BuilderInstruction {
|
|
|
|
BuilderInstruction::new(
|
|
|
|
system_program::id(),
|
|
|
|
&SystemInstruction::CreateAccount {
|
|
|
|
tokens,
|
|
|
|
space,
|
|
|
|
program_id,
|
|
|
|
},
|
|
|
|
vec![(from_id, true), (to_id, false)],
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-02-28 04:48:44 -07:00
|
|
|
pub fn new_move(from_id: Pubkey, to_id: Pubkey, tokens: u64) -> BuilderInstruction {
|
|
|
|
BuilderInstruction::new(
|
|
|
|
system_program::id(),
|
|
|
|
&SystemInstruction::Move { tokens },
|
|
|
|
vec![(from_id, true), (to_id, false)],
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|