Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Add StakeState::serialized_size and static assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarry committed Apr 19, 2022
1 parent d6ff50b commit dc0cc89
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 125 deletions.
2 changes: 1 addition & 1 deletion cli/src/cluster_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2113,7 +2113,7 @@ impl RentLengthValue {
pub fn length(&self) -> usize {
match self {
Self::Nonce => NonceState::size(),
Self::Stake => std::mem::size_of::<StakeState>(),
Self::Stake => StakeState::serialized_size(),
Self::System => 0,
Self::Vote => VoteState::size_of(),
Self::Bytes(l) => *l,
Expand Down
4 changes: 2 additions & 2 deletions cli/src/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,7 @@ pub fn process_create_stake_account(
}

let minimum_balance =
rpc_client.get_minimum_balance_for_rent_exemption(std::mem::size_of::<StakeState>())?;
rpc_client.get_minimum_balance_for_rent_exemption(StakeState::serialized_size())?;

if lamports < minimum_balance {
return Err(CliError::BadParameter(format!(
Expand Down Expand Up @@ -1784,7 +1784,7 @@ pub fn process_split_stake(
}

let minimum_balance =
rpc_client.get_minimum_balance_for_rent_exemption(std::mem::size_of::<StakeState>())?;
rpc_client.get_minimum_balance_for_rent_exemption(StakeState::serialized_size())?;

if lamports < minimum_balance {
return Err(CliError::BadParameter(format!(
Expand Down
4 changes: 2 additions & 2 deletions cli/tests/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ fn test_stake_split() {

// Create stake account, identity is authority
let minimum_stake_balance = rpc_client
.get_minimum_balance_for_rent_exemption(std::mem::size_of::<StakeState>())
.get_minimum_balance_for_rent_exemption(StakeState::serialized_size())
.unwrap();
let stake_keypair = keypair_from_seed(&[0u8; 32]).unwrap();
let stake_account_pubkey = stake_keypair.pubkey();
Expand Down Expand Up @@ -1227,7 +1227,7 @@ fn test_stake_set_lockup() {

// Create stake account, identity is authority
let minimum_stake_balance = rpc_client
.get_minimum_balance_for_rent_exemption(std::mem::size_of::<StakeState>())
.get_minimum_balance_for_rent_exemption(StakeState::serialized_size())
.unwrap();

let stake_keypair = keypair_from_seed(&[0u8; 32]).unwrap();
Expand Down
Loading

0 comments on commit dc0cc89

Please sign in to comment.