Skip to content

Commit f35ce52

Browse files
authored
Turn minimum function into constant (#280)
1 parent 825b7ec commit f35ce52

File tree

4 files changed

+7
-11
lines changed

4 files changed

+7
-11
lines changed

program/rust/src/c_oracle_header.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ pub trait PythAccount: Pod {
3737
const INITIAL_SIZE: u32;
3838
/// `minimum_size()` is the minimum size that the solana account holding the struct needs to
3939
/// have. `INITIAL_SIZE` <= `minimum_size()`
40-
fn minimum_size() -> usize {
41-
size_of::<Self>()
42-
}
40+
const MINIMUM_SIZE: usize = size_of::<Self>();
4341
}
4442

4543
impl PythAccount for MappingAccount {
@@ -51,9 +49,7 @@ impl PythAccount for MappingAccount {
5149
impl PythAccount for ProductAccount {
5250
const ACCOUNT_TYPE: u32 = PC_ACCTYPE_PRODUCT;
5351
const INITIAL_SIZE: u32 = size_of::<ProductAccount>() as u32;
54-
fn minimum_size() -> usize {
55-
PC_PROD_ACC_SIZE as usize
56-
}
52+
const MINIMUM_SIZE: usize = PC_PROD_ACC_SIZE as usize;
5753
}
5854

5955
impl PythAccount for PriceAccount {

program/rust/src/deserialize.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub fn load_checked<'a, T: PythAccount>(
7474
version: u32,
7575
) -> Result<RefMut<'a, T>, ProgramError> {
7676
pyth_assert(
77-
account.data_len() >= T::minimum_size(),
77+
account.data_len() >= T::MINIMUM_SIZE,
7878
OracleError::AccountTooSmall.into(),
7979
)?;
8080

@@ -96,7 +96,7 @@ pub fn initialize_pyth_account_checked<'a, T: PythAccount>(
9696
version: u32,
9797
) -> Result<RefMut<'a, T>, ProgramError> {
9898
pyth_assert(
99-
account.data_len() >= T::minimum_size(),
99+
account.data_len() >= T::MINIMUM_SIZE,
100100
OracleError::AccountTooSmall.into(),
101101
)?;
102102
check_valid_fresh_account(account)?;

program/rust/src/tests/test_add_publisher.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn test_add_publisher() {
5656

5757
// Now give the price account enough lamports to be rent exempt
5858
**price_account.try_borrow_mut_lamports().unwrap() =
59-
Rent::minimum_balance(&Rent::default(), PriceAccount::minimum_size());
59+
Rent::minimum_balance(&Rent::default(), PriceAccount::MINIMUM_SIZE);
6060

6161

6262
assert!(process_instruction(

program/rust/src/tests/test_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ impl AccountSetup {
4343
pub fn new<T: PythAccount>(owner: &Pubkey) -> Self {
4444
let key = Pubkey::new_unique();
4545
let owner = owner.clone();
46-
let balance = Rent::minimum_balance(&Rent::default(), T::minimum_size());
47-
let size = T::minimum_size();
46+
let balance = Rent::minimum_balance(&Rent::default(), T::MINIMUM_SIZE);
47+
let size = T::MINIMUM_SIZE;
4848
let data = [0; UPPER_BOUND_OF_ALL_ACCOUNT_SIZES];
4949
return AccountSetup {
5050
key,

0 commit comments

Comments
 (0)