Rename SystemInstruction::Move to SystemInstruction::Transfer

This commit is contained in:
Greg Fitzgerald
2019-04-02 21:52:07 -06:00
parent 43bb813cbe
commit 867f6f107b
24 changed files with 137 additions and 85 deletions

View File

@ -35,13 +35,13 @@ mod tests {
// One signature, a fee.
let pubkey0 = Pubkey::new(&[0; 32]);
let pubkey1 = Pubkey::new(&[1; 32]);
let ix0 = SystemInstruction::new_move(&pubkey0, &pubkey1, 1);
let ix0 = SystemInstruction::new_transfer(&pubkey0, &pubkey1, 1);
let message = Message::new(vec![ix0]);
assert_eq!(FeeCalculator::new(2).calculate_fee(&message), 2);
// Two signatures, double the fee.
let ix0 = SystemInstruction::new_move(&pubkey0, &pubkey1, 1);
let ix1 = SystemInstruction::new_move(&pubkey1, &pubkey0, 1);
let ix0 = SystemInstruction::new_transfer(&pubkey0, &pubkey1, 1);
let ix1 = SystemInstruction::new_transfer(&pubkey1, &pubkey0, 1);
let message = Message::new(vec![ix0, ix1]);
assert_eq!(FeeCalculator::new(2).calculate_fee(&message), 4);
}

View File

@ -25,10 +25,10 @@ pub enum SystemInstruction {
/// Assign account to a program
/// * Transaction::keys[0] - account to assign
Assign { program_id: Pubkey },
/// Move lamports
/// Transfer lamports
/// * Transaction::keys[0] - source
/// * Transaction::keys[1] - destination
Move { lamports: u64 },
Transfer { lamports: u64 },
}
impl SystemInstruction {
@ -71,23 +71,23 @@ impl SystemInstruction {
)
}
pub fn new_move(from_id: &Pubkey, to_id: &Pubkey, lamports: u64) -> Instruction {
pub fn new_transfer(from_id: &Pubkey, to_id: &Pubkey, lamports: u64) -> Instruction {
let account_metas = vec![
AccountMeta::new(*from_id, true),
AccountMeta::new(*to_id, false),
];
Instruction::new(
system_program::id(),
&SystemInstruction::Move { lamports },
&SystemInstruction::Transfer { lamports },
account_metas,
)
}
/// Create and sign new SystemInstruction::Move transaction to many destinations
pub fn new_move_many(from_id: &Pubkey, to_lamports: &[(Pubkey, u64)]) -> Vec<Instruction> {
/// Create and sign new SystemInstruction::Transfer transaction to many destinations
pub fn new_transfer_many(from_id: &Pubkey, to_lamports: &[(Pubkey, u64)]) -> Vec<Instruction> {
to_lamports
.iter()
.map(|(to_id, lamports)| SystemInstruction::new_move(from_id, to_id, *lamports))
.map(|(to_id, lamports)| SystemInstruction::new_transfer(from_id, to_id, *lamports))
.collect()
}
}
@ -107,7 +107,7 @@ mod tests {
let carol_pubkey = Pubkey::new_rand();
let to_lamports = vec![(bob_pubkey, 1), (carol_pubkey, 2)];
let instructions = SystemInstruction::new_move_many(&alice_pubkey, &to_lamports);
let instructions = SystemInstruction::new_transfer_many(&alice_pubkey, &to_lamports);
assert_eq!(instructions.len(), 2);
assert_eq!(get_keys(&instructions[0]), vec![alice_pubkey, bob_pubkey]);
assert_eq!(get_keys(&instructions[1]), vec![alice_pubkey, carol_pubkey]);

View File

@ -60,8 +60,8 @@ impl SystemTransaction {
Transaction::new_signed_instructions(&[from_keypair], instructions, recent_blockhash)
}
/// Create and sign new SystemInstruction::Move transaction
pub fn new_move(
/// Create and sign new SystemInstruction::Transfer transaction
pub fn new_transfer(
from_keypair: &Keypair,
to: &Pubkey,
lamports: u64,
@ -69,7 +69,7 @@ impl SystemTransaction {
_fee: u64,
) -> Transaction {
let from_pubkey = from_keypair.pubkey();
let move_instruction = SystemInstruction::new_move(&from_pubkey, to, lamports);
let move_instruction = SystemInstruction::new_transfer(&from_pubkey, to, lamports);
let instructions = vec![move_instruction];
Transaction::new_signed_instructions(&[from_keypair], instructions, recent_blockhash)
}

View File

@ -321,7 +321,7 @@ mod tests {
let alice_keypair = Keypair::new();
let alice_pubkey = alice_keypair.pubkey();
let bob_pubkey = Pubkey::new_rand();
let ix = SystemInstruction::new_move(&alice_pubkey, &bob_pubkey, 42);
let ix = SystemInstruction::new_transfer(&alice_pubkey, &bob_pubkey, 42);
let expected_data_size = size_of::<u32>() + size_of::<u64>();
assert_eq!(expected_data_size, 12);