Move new_move_many to SystemInstruction
This commit is contained in:
@ -82,4 +82,35 @@ impl SystemInstruction {
|
||||
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> {
|
||||
to_lamports
|
||||
.iter()
|
||||
.map(|(to_id, lamports)| SystemInstruction::new_move(from_id, to_id, *lamports))
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::signature::{Keypair, KeypairUtil};
|
||||
|
||||
fn get_keys(instruction: &Instruction) -> Vec<Pubkey> {
|
||||
instruction.accounts.iter().map(|x| x.pubkey).collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_move_many() {
|
||||
let alice_pubkey = Keypair::new().pubkey();
|
||||
let bob_pubkey = Keypair::new().pubkey();
|
||||
let carol_pubkey = Keypair::new().pubkey();
|
||||
let to_lamports = vec![(bob_pubkey, 1), (carol_pubkey, 2)];
|
||||
|
||||
let instructions = SystemInstruction::new_move_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]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user