parent
08e73e5366
commit
77c3a1f372
|
@ -103,6 +103,10 @@ fn process_rebase_stake_accounts(
|
||||||
&args.stake_authority.pubkey(),
|
&args.stake_authority.pubkey(),
|
||||||
&balances,
|
&balances,
|
||||||
);
|
);
|
||||||
|
if messages.is_empty() {
|
||||||
|
eprintln!("No accounts found");
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
let signers = vec![
|
let signers = vec![
|
||||||
&*args.fee_payer,
|
&*args.fee_payer,
|
||||||
&*args.new_base_keypair,
|
&*args.new_base_keypair,
|
||||||
|
@ -134,6 +138,10 @@ fn process_move_stake_accounts(
|
||||||
&authorize_args.new_withdraw_authority,
|
&authorize_args.new_withdraw_authority,
|
||||||
&balances,
|
&balances,
|
||||||
);
|
);
|
||||||
|
if messages.is_empty() {
|
||||||
|
eprintln!("No accounts found");
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
let signers = vec![
|
let signers = vec![
|
||||||
&*args.fee_payer,
|
&*args.fee_payer,
|
||||||
&*args.new_base_keypair,
|
&*args.new_base_keypair,
|
||||||
|
|
|
@ -73,7 +73,10 @@ fn rebase_stake_account(
|
||||||
fee_payer_pubkey: &Pubkey,
|
fee_payer_pubkey: &Pubkey,
|
||||||
stake_authority_pubkey: &Pubkey,
|
stake_authority_pubkey: &Pubkey,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
) -> Message {
|
) -> Option<Message> {
|
||||||
|
if lamports == 0 {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
let new_stake_account_address = derive_stake_account_address(new_base_pubkey, i);
|
let new_stake_account_address = derive_stake_account_address(new_base_pubkey, i);
|
||||||
let instructions = stake_instruction::split_with_seed(
|
let instructions = stake_instruction::split_with_seed(
|
||||||
stake_account_address,
|
stake_account_address,
|
||||||
|
@ -83,7 +86,8 @@ fn rebase_stake_account(
|
||||||
new_base_pubkey,
|
new_base_pubkey,
|
||||||
&i.to_string(),
|
&i.to_string(),
|
||||||
);
|
);
|
||||||
Message::new_with_payer(&instructions, Some(&fee_payer_pubkey))
|
let message = Message::new_with_payer(&instructions, Some(&fee_payer_pubkey));
|
||||||
|
Some(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn move_stake_account(
|
fn move_stake_account(
|
||||||
|
@ -96,7 +100,10 @@ fn move_stake_account(
|
||||||
new_stake_authority_pubkey: &Pubkey,
|
new_stake_authority_pubkey: &Pubkey,
|
||||||
new_withdraw_authority_pubkey: &Pubkey,
|
new_withdraw_authority_pubkey: &Pubkey,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
) -> Message {
|
) -> Option<Message> {
|
||||||
|
if lamports == 0 {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
let new_stake_account_address = derive_stake_account_address(new_base_pubkey, i);
|
let new_stake_account_address = derive_stake_account_address(new_base_pubkey, i);
|
||||||
let mut instructions = stake_instruction::split_with_seed(
|
let mut instructions = stake_instruction::split_with_seed(
|
||||||
stake_account_address,
|
stake_account_address,
|
||||||
|
@ -116,7 +123,8 @@ fn move_stake_account(
|
||||||
);
|
);
|
||||||
|
|
||||||
instructions.extend(authorize_instructions.into_iter());
|
instructions.extend(authorize_instructions.into_iter());
|
||||||
Message::new_with_payer(&instructions, Some(&fee_payer_pubkey))
|
let message = Message::new_with_payer(&instructions, Some(&fee_payer_pubkey));
|
||||||
|
Some(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn authorize_stake_accounts(
|
pub(crate) fn authorize_stake_accounts(
|
||||||
|
@ -153,7 +161,7 @@ pub(crate) fn rebase_stake_accounts(
|
||||||
balances
|
balances
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, (stake_account_address, lamports))| {
|
.filter_map(|(i, (stake_account_address, lamports))| {
|
||||||
rebase_stake_account(
|
rebase_stake_account(
|
||||||
stake_account_address,
|
stake_account_address,
|
||||||
new_base_pubkey,
|
new_base_pubkey,
|
||||||
|
@ -178,7 +186,7 @@ pub(crate) fn move_stake_accounts(
|
||||||
balances
|
balances
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, (stake_account_address, lamports))| {
|
.filter_map(|(i, (stake_account_address, lamports))| {
|
||||||
move_stake_account(
|
move_stake_account(
|
||||||
stake_account_address,
|
stake_account_address,
|
||||||
new_base_pubkey,
|
new_base_pubkey,
|
||||||
|
@ -339,6 +347,22 @@ mod tests {
|
||||||
assert_eq!(authorized.withdrawer, new_withdraw_authority_pubkey);
|
assert_eq!(authorized.withdrawer, new_withdraw_authority_pubkey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_rebase_empty_account() {
|
||||||
|
let pubkey = Pubkey::default();
|
||||||
|
let message = rebase_stake_account(&pubkey, &pubkey, 0, &pubkey, &pubkey, 0);
|
||||||
|
assert_eq!(message, None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_move_empty_account() {
|
||||||
|
let pubkey = Pubkey::default();
|
||||||
|
let message = move_stake_account(
|
||||||
|
&pubkey, &pubkey, 0, &pubkey, &pubkey, &pubkey, &pubkey, &pubkey, 0,
|
||||||
|
);
|
||||||
|
assert_eq!(message, None);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rebase_stake_accounts() {
|
fn test_rebase_stake_accounts() {
|
||||||
let (bank, funding_keypair, rent) = create_bank(10_000_000);
|
let (bank, funding_keypair, rent) = create_bank(10_000_000);
|
||||||
|
|
Loading…
Reference in New Issue