@@ -310,11 +310,12 @@ decl_module! {
310
310
gas_limit,
311
311
gas_price,
312
312
nonce,
313
+ true ,
313
314
) ? {
314
- ExitReason :: Succeed ( _) => {
315
+ ( ExitReason :: Succeed ( _ ) , _ , _) => {
315
316
Module :: <T >:: deposit_event( Event :: <T >:: Executed ( target) ) ;
316
317
} ,
317
- ExitReason :: Error ( _ ) | ExitReason :: Revert ( _ ) | ExitReason :: Fatal ( _) => {
318
+ ( _ , _ , _) => {
318
319
Module :: <T >:: deposit_event( Event :: <T >:: ExecutedFailed ( target) ) ;
319
320
} ,
320
321
}
@@ -344,12 +345,13 @@ decl_module! {
344
345
value,
345
346
gas_limit,
346
347
gas_price,
347
- nonce
348
+ nonce,
349
+ true ,
348
350
) ? {
349
- ( create_address , ExitReason :: Succeed ( _) ) => {
351
+ ( ExitReason :: Succeed ( _) , create_address , _ ) => {
350
352
Module :: <T >:: deposit_event( Event :: <T >:: Created ( create_address) ) ;
351
353
} ,
352
- ( create_address, _) => {
354
+ ( _ , create_address, _) => {
353
355
Module :: <T >:: deposit_event( Event :: <T >:: CreatedFailed ( create_address) ) ;
354
356
} ,
355
357
}
@@ -380,12 +382,13 @@ decl_module! {
380
382
value,
381
383
gas_limit,
382
384
gas_price,
383
- nonce
385
+ nonce,
386
+ true ,
384
387
) ? {
385
- ( create_address , ExitReason :: Succeed ( _) ) => {
388
+ ( ExitReason :: Succeed ( _) , create_address , _ ) => {
386
389
Module :: <T >:: deposit_event( Event :: <T >:: Created ( create_address) ) ;
387
390
} ,
388
- ( create_address, _) => {
391
+ ( _ , create_address, _) => {
389
392
Module :: <T >:: deposit_event( Event :: <T >:: CreatedFailed ( create_address) ) ;
390
393
} ,
391
394
}
@@ -435,23 +438,26 @@ impl<T: Trait> Module<T> {
435
438
value : U256 ,
436
439
gas_limit : u32 ,
437
440
gas_price : U256 ,
438
- nonce : Option < U256 >
439
- ) -> Result < ( H160 , ExitReason ) , Error < T > > {
441
+ nonce : Option < U256 > ,
442
+ apply_state : bool ,
443
+ ) -> Result < ( ExitReason , H160 , U256 ) , Error < T > > {
440
444
Self :: execute_evm (
441
445
source,
442
446
value,
443
447
gas_limit,
444
448
gas_price,
445
449
nonce,
450
+ apply_state,
446
451
|executor| {
447
- ( executor. create_address (
452
+ let address = executor. create_address (
448
453
evm:: CreateScheme :: Legacy { caller : source } ,
449
- ) , executor. transact_create (
454
+ ) ;
455
+ ( executor. transact_create (
450
456
source,
451
457
value,
452
458
init,
453
459
gas_limit as usize ,
454
- ) )
460
+ ) , address )
455
461
} ,
456
462
)
457
463
}
@@ -464,25 +470,28 @@ impl<T: Trait> Module<T> {
464
470
value : U256 ,
465
471
gas_limit : u32 ,
466
472
gas_price : U256 ,
467
- nonce : Option < U256 >
468
- ) -> Result < ( H160 , ExitReason ) , Error < T > > {
473
+ nonce : Option < U256 > ,
474
+ apply_state : bool ,
475
+ ) -> Result < ( ExitReason , H160 , U256 ) , Error < T > > {
469
476
let code_hash = H256 :: from_slice ( Keccak256 :: digest ( & init) . as_slice ( ) ) ;
470
477
Self :: execute_evm (
471
478
source,
472
479
value,
473
480
gas_limit,
474
481
gas_price,
475
482
nonce,
483
+ apply_state,
476
484
|executor| {
477
- ( executor. create_address (
485
+ let address = executor. create_address (
478
486
evm:: CreateScheme :: Create2 { caller : source, code_hash, salt } ,
479
- ) , executor. transact_create2 (
487
+ ) ;
488
+ ( executor. transact_create2 (
480
489
source,
481
490
value,
482
491
init,
483
492
salt,
484
493
gas_limit as usize ,
485
- ) )
494
+ ) , address )
486
495
} ,
487
496
)
488
497
}
@@ -496,21 +505,23 @@ impl<T: Trait> Module<T> {
496
505
gas_limit : u32 ,
497
506
gas_price : U256 ,
498
507
nonce : Option < U256 > ,
499
- ) -> Result < ExitReason , Error < T > > {
500
- Ok ( Self :: execute_evm (
508
+ apply_state : bool ,
509
+ ) -> Result < ( ExitReason , Vec < u8 > , U256 ) , Error < T > > {
510
+ Self :: execute_evm (
501
511
source,
502
512
value,
503
513
gas_limit,
504
514
gas_price,
505
515
nonce,
506
- |executor| ( ( ) , executor. transact_call (
516
+ apply_state,
517
+ |executor| executor. transact_call (
507
518
source,
508
519
target,
509
520
value,
510
521
input,
511
522
gas_limit as usize ,
512
- ) ) ,
513
- ) ? . 1 )
523
+ ) ,
524
+ )
514
525
}
515
526
516
527
/// Execute an EVM operation.
@@ -520,9 +531,10 @@ impl<T: Trait> Module<T> {
520
531
gas_limit : u32 ,
521
532
gas_price : U256 ,
522
533
nonce : Option < U256 > ,
534
+ apply_state : bool ,
523
535
f : F ,
524
- ) -> Result < ( R , ExitReason ) , Error < T > > where
525
- F : FnOnce ( & mut StackExecutor < Backend < T > > ) -> ( R , ExitReason ) ,
536
+ ) -> Result < ( ExitReason , R , U256 ) , Error < T > > where
537
+ F : FnOnce ( & mut StackExecutor < Backend < T > > ) -> ( ExitReason , R ) ,
526
538
{
527
539
let vicinity = Vicinity {
528
540
gas_price,
@@ -550,12 +562,15 @@ impl<T: Trait> Module<T> {
550
562
551
563
let ( retv, reason) = f ( & mut executor) ;
552
564
565
+ let used_gas = U256 :: from ( executor. used_gas ( ) ) ;
553
566
let actual_fee = executor. fee ( gas_price) ;
554
567
executor. deposit ( source, total_fee. saturating_sub ( actual_fee) ) ;
555
568
556
- let ( values, logs) = executor. deconstruct ( ) ;
557
- backend. apply ( values, logs, true ) ;
569
+ if apply_state {
570
+ let ( values, logs) = executor. deconstruct ( ) ;
571
+ backend. apply ( values, logs, true ) ;
572
+ }
558
573
559
- Ok ( ( retv, reason) )
574
+ Ok ( ( retv, reason, used_gas ) )
560
575
}
561
576
}
0 commit comments