1
+ use super :: fee:: charge_fee;
1
2
use super :: { verify_version, Transaction } ;
2
3
use crate :: core:: contract_address:: { compute_casm_class_hash, compute_sierra_class_hash} ;
3
4
use crate :: definitions:: constants:: QUERY_VERSION_BASE ;
@@ -13,23 +14,18 @@ use crate::{
13
14
transaction_type:: TransactionType ,
14
15
} ,
15
16
execution:: {
16
- execution_entry_point:: ExecutionEntryPoint , CallInfo , CallType ,
17
- TransactionExecutionContext , TransactionExecutionInfo ,
17
+ execution_entry_point:: ExecutionEntryPoint , CallType , TransactionExecutionContext ,
18
+ TransactionExecutionInfo ,
18
19
} ,
19
20
state:: state_api:: { State , StateReader } ,
20
21
state:: ExecutionResourcesManager ,
21
- transaction:: {
22
- error:: TransactionError ,
23
- fee:: { calculate_tx_fee, execute_fee_transfer, FeeInfo } ,
24
- invoke_function:: verify_no_calls_to_other_contracts,
25
- } ,
22
+ transaction:: { error:: TransactionError , invoke_function:: verify_no_calls_to_other_contracts} ,
26
23
utils:: { calculate_tx_resources, Address } ,
27
24
} ;
28
25
use cairo_lang_starknet:: casm_contract_class:: CasmContractClass ;
29
26
use cairo_lang_starknet:: contract_class:: ContractClass as SierraContractClass ;
30
27
use cairo_vm:: felt:: Felt252 ;
31
28
use num_traits:: Zero ;
32
- use std:: collections:: HashMap ;
33
29
34
30
/// Represents a declare transaction in the starknet network.
35
31
/// Declare creates a blueprint of a contract class that is used to deploy instances of the contract
@@ -274,43 +270,6 @@ impl DeclareV2 {
274
270
Vec :: from ( [ bytes] )
275
271
}
276
272
277
- /// Calculates and charges the actual fee.
278
- /// ## Parameter:
279
- /// - state: An state that implements the State and StateReader traits.
280
- /// - resources: the resources that are in use by the contract
281
- /// - block_context: The block that contains the execution context
282
- pub fn charge_fee < S : StateReader > (
283
- & self ,
284
- state : & mut CachedState < S > ,
285
- resources : & HashMap < String , usize > ,
286
- block_context : & BlockContext ,
287
- ) -> Result < FeeInfo , TransactionError > {
288
- if self . max_fee . is_zero ( ) {
289
- return Ok ( ( None , 0 ) ) ;
290
- }
291
-
292
- let actual_fee = calculate_tx_fee (
293
- resources,
294
- block_context. starknet_os_config . gas_price ,
295
- block_context,
296
- ) ?;
297
-
298
- let mut tx_execution_context =
299
- self . get_execution_context ( block_context. invoke_tx_max_n_steps ) ;
300
- let fee_transfer_info = if self . skip_fee_transfer {
301
- None
302
- } else {
303
- Some ( execute_fee_transfer (
304
- state,
305
- block_context,
306
- & mut tx_execution_context,
307
- actual_fee,
308
- ) ?)
309
- } ;
310
-
311
- Ok ( ( fee_transfer_info, actual_fee) )
312
- }
313
-
314
273
// TODO: delete once used
315
274
#[ allow( dead_code) ]
316
275
fn handle_nonce < S : State + StateReader > ( & self , state : & mut S ) -> Result < ( ) , TransactionError > {
@@ -347,33 +306,42 @@ impl DeclareV2 {
347
306
348
307
let mut resources_manager = ExecutionResourcesManager :: default ( ) ;
349
308
350
- let ( validate_info , _remaining_gas) = if self . skip_validate {
351
- ( None , 0 )
309
+ let ( execution_result , _remaining_gas) = if self . skip_validate {
310
+ ( ExecutionResult :: default ( ) , 0 )
352
311
} else {
353
312
let ( info, gas) = self . run_validate_entrypoint (
354
313
initial_gas,
355
314
state,
356
315
& mut resources_manager,
357
316
block_context,
358
317
) ?;
359
- ( Some ( info) , gas)
318
+ ( info, gas)
360
319
} ;
361
320
362
321
let storage_changes = state. count_actual_storage_changes ( ) ;
363
322
let actual_resources = calculate_tx_resources (
364
323
resources_manager,
365
- & [ validate_info . clone ( ) ] ,
324
+ & [ execution_result . call_info . clone ( ) ] ,
366
325
self . tx_type ,
367
326
storage_changes,
368
327
None ,
328
+ execution_result. n_reverted_steps ,
369
329
) ?;
370
330
371
- let ( fee_transfer_info, actual_fee) =
372
- self . charge_fee ( state, & actual_resources, block_context) ?;
331
+ let mut tx_execution_context =
332
+ self . get_execution_context ( block_context. invoke_tx_max_n_steps ) ;
333
+ let ( fee_transfer_info, actual_fee) = charge_fee (
334
+ state,
335
+ & actual_resources,
336
+ block_context,
337
+ self . max_fee ,
338
+ & mut tx_execution_context,
339
+ self . skip_fee_transfer ,
340
+ ) ?;
373
341
self . compile_and_store_casm_class ( state) ?;
374
342
375
343
let mut tx_exec_info = TransactionExecutionInfo :: new_without_fee_info (
376
- validate_info ,
344
+ execution_result . call_info ,
377
345
None ,
378
346
None ,
379
347
actual_resources,
@@ -415,7 +383,7 @@ impl DeclareV2 {
415
383
state : & mut CachedState < S > ,
416
384
resources_manager : & mut ExecutionResourcesManager ,
417
385
block_context : & BlockContext ,
418
- ) -> Result < ( CallInfo , u128 ) , TransactionError > {
386
+ ) -> Result < ( ExecutionResult , u128 ) , TransactionError > {
419
387
let calldata = [ self . compiled_class_hash . clone ( ) ] . to_vec ( ) ;
420
388
421
389
let entry_point = ExecutionEntryPoint {
@@ -433,7 +401,7 @@ impl DeclareV2 {
433
401
let mut tx_execution_context =
434
402
self . get_execution_context ( block_context. validate_max_n_steps ) ;
435
403
436
- let ExecutionResult { call_info , .. } = if self . skip_execute {
404
+ let execution_result = if self . skip_execute {
437
405
ExecutionResult :: default ( )
438
406
} else {
439
407
entry_point. execute (
@@ -445,10 +413,13 @@ impl DeclareV2 {
445
413
block_context. validate_max_n_steps ,
446
414
) ?
447
415
} ;
448
- let call_info = verify_no_calls_to_other_contracts ( & call_info) ?;
449
- remaining_gas -= call_info. gas_consumed ;
450
416
451
- Ok ( ( call_info, remaining_gas) )
417
+ if execution_result. call_info . is_some ( ) {
418
+ verify_no_calls_to_other_contracts ( & execution_result. call_info ) ?;
419
+ remaining_gas -= execution_result. call_info . clone ( ) . unwrap ( ) . gas_consumed ;
420
+ }
421
+
422
+ Ok ( ( execution_result, remaining_gas) )
452
423
}
453
424
454
425
// ---------------
0 commit comments