Skip to content

Commit 36bae1a

Browse files
authored
Cleanup resize, remove print staments, add extra check (#272)
1 parent 8f0b980 commit 36bae1a

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

program/rust/src/rust_oracle.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,14 @@ pub fn resize_price_account(
120120
check_id(system_program.key),
121121
OracleError::InvalidSystemAccount.into(),
122122
)?;
123-
//throw an error if not a price account
124-
//need to makre sure it goes out of scope immediatly to avoid mutable borrow errors
123+
// Check that it is a valid initialized price account
125124
{
126125
load_checked::<PriceAccount>(price_account_info, PC_VERSION)?;
127126
}
128127
let account_len = price_account_info.try_data_len()?;
129128
match account_len {
130129
PRICE_T_SIZE => {
131-
//ensure account is still rent exempt after resizing
130+
// Ensure account is still rent exempt after resizing
132131
let rent: Rent = Default::default();
133132
let lamports_needed: u64 = rent
134133
.minimum_balance(size_of::<PriceAccountWrapper>())
@@ -141,15 +140,19 @@ pub fn resize_price_account(
141140
lamports_needed,
142141
)?;
143142
}
144-
//resize
145-
//we do not need to zero initialize since this is the first time this memory
146-
//is allocated
143+
// We do not need to zero allocate because we won't access the data in the same
144+
// instruction
147145
price_account_info.realloc(size_of::<PriceAccountWrapper>(), false)?;
148-
//The load below would fail if the account was not a price account, reverting the whole
149-
// transaction
146+
147+
// Check that everything is ok
148+
check_valid_signable_account(
149+
program_id,
150+
price_account_info,
151+
size_of::<PriceAccountWrapper>(),
152+
)?;
150153
let mut price_account =
151154
load_checked::<PriceAccountWrapper>(price_account_info, PC_VERSION)?;
152-
//Initialize Time Machine
155+
// Initialize Time Machine
153156
price_account.initialize_time_machine()?;
154157
Ok(())
155158
}

program/rust/src/time_machine_types.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use bytemuck::{
1010
Pod,
1111
Zeroable,
1212
};
13-
use solana_program::msg;
1413

1514

1615
#[derive(Debug, Clone, Copy)]
@@ -35,12 +34,12 @@ pub struct PriceAccountWrapper {
3534
}
3635
impl PriceAccountWrapper {
3736
pub fn initialize_time_machine(&mut self) -> Result<(), OracleError> {
38-
msg!("implement me");
37+
// TO DO
3938
Ok(())
4039
}
4140

4241
pub fn add_price_to_time_machine(&mut self) -> Result<(), OracleError> {
43-
msg!("implement me");
42+
// TO DO
4443
Ok(())
4544
}
4645
}

0 commit comments

Comments
 (0)