Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 01f74fe

Browse files
authored
Merge branch 'main' into docs_hash_utils
2 parents 340605f + 7d9a628 commit 01f74fe

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

src/transaction/declare.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -262,30 +262,36 @@ impl Declare {
262262
Ok(())
263263
}
264264

265-
/// Calculates actual fee used by the transaction using the execution
266-
/// info returned by apply(), then updates the transaction execution info with the data of the fee.
267-
pub fn execute<S: State + StateReader>(
265+
fn set_contract_class<S: State + StateReader>(
268266
&self,
269267
state: &mut S,
270-
block_context: &BlockContext,
271-
) -> Result<TransactionExecutionInfo, TransactionError> {
272-
let mut tx_exec_info = self.apply(state, block_context)?;
273-
self.handle_nonce(state)?;
274-
// Set contract class
268+
) -> Result<(), TransactionError> {
275269
match state.get_contract_class(&self.class_hash) {
276270
Err(StateError::NoneCompiledHash(_)) => {
277271
// Class is undeclared; declare it.
278272
state.set_contract_class(&self.class_hash, &self.contract_class)?;
273+
Ok(())
279274
}
280-
Err(error) => return Err(error.into()),
275+
Err(error) => Err(error.into()),
281276
Ok(_) => {
282277
// Class is already declared; cannot redeclare.
283-
return Err(TransactionError::ClassAlreadyDeclared(self.class_hash));
278+
Err(TransactionError::ClassAlreadyDeclared(self.class_hash))
284279
}
285280
}
281+
}
282+
/// Calculates actual fee used by the transaction using the execution
283+
/// info returned by apply(), then updates the transaction execution info with the data of the fee.
284+
pub fn execute<S: State + StateReader>(
285+
&self,
286+
state: &mut S,
287+
block_context: &BlockContext,
288+
) -> Result<TransactionExecutionInfo, TransactionError> {
289+
let mut tx_exec_info = self.apply(state, block_context)?;
290+
self.handle_nonce(state)?;
286291

287292
let (fee_transfer_info, actual_fee) =
288293
self.charge_fee(state, &tx_exec_info.actual_resources, block_context)?;
294+
self.set_contract_class(state)?;
289295
tx_exec_info.set_fee_info(actual_fee, fee_transfer_info);
290296

291297
Ok(tx_exec_info)

src/transaction/declare_v2.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,9 @@ impl DeclareV2 {
222222
None,
223223
)?;
224224

225-
self.compile_and_store_casm_class(state)?;
226-
227225
let (fee_transfer_info, actual_fee) =
228226
self.charge_fee(state, &actual_resources, block_context)?;
227+
self.compile_and_store_casm_class(state)?;
229228

230229
let mut tx_exec_info = TransactionExecutionInfo::new_without_fee_info(
231230
validate_info,

0 commit comments

Comments
 (0)