@@ -120,15 +120,14 @@ pub fn resize_price_account(
120
120
check_id ( system_program. key ) ,
121
121
OracleError :: InvalidSystemAccount . into ( ) ,
122
122
) ?;
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
125
124
{
126
125
load_checked :: < PriceAccount > ( price_account_info, PC_VERSION ) ?;
127
126
}
128
127
let account_len = price_account_info. try_data_len ( ) ?;
129
128
match account_len {
130
129
PRICE_T_SIZE => {
131
- //ensure account is still rent exempt after resizing
130
+ // Ensure account is still rent exempt after resizing
132
131
let rent: Rent = Default :: default ( ) ;
133
132
let lamports_needed: u64 = rent
134
133
. minimum_balance ( size_of :: < PriceAccountWrapper > ( ) )
@@ -141,15 +140,19 @@ pub fn resize_price_account(
141
140
lamports_needed,
142
141
) ?;
143
142
}
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
147
145
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
+ ) ?;
150
153
let mut price_account =
151
154
load_checked :: < PriceAccountWrapper > ( price_account_info, PC_VERSION ) ?;
152
- //Initialize Time Machine
155
+ // Initialize Time Machine
153
156
price_account. initialize_time_machine ( ) ?;
154
157
Ok ( ( ) )
155
158
}
0 commit comments