@@ -385,12 +385,12 @@ impl MockTransaction {
385
385
386
386
/// Gets the priority fee for dynamic fee transactions (EIP-1559 and EIP-4844)
387
387
pub fn get_priority_fee ( & self ) -> Option < u128 > {
388
- if let MockTransaction :: Eip1559 { max_priority_fee_per_gas , .. } |
389
- MockTransaction :: Eip4844 { max_priority_fee_per_gas, .. } = self
390
- {
391
- Some ( * max_priority_fee_per_gas)
392
- } else {
393
- None
388
+ match self {
389
+ MockTransaction :: Eip1559 { max_priority_fee_per_gas, .. } |
390
+ MockTransaction :: Eip4844 { max_priority_fee_per_gas , .. } => {
391
+ Some ( * max_priority_fee_per_gas)
392
+ }
393
+ _ => None ,
394
394
}
395
395
}
396
396
@@ -412,25 +412,19 @@ impl MockTransaction {
412
412
413
413
/// Gets the max fee for dynamic fee transactions (EIP-1559 and EIP-4844)
414
414
pub fn get_max_fee ( & self ) -> Option < u128 > {
415
- if let MockTransaction :: Eip1559 { max_fee_per_gas, .. } |
416
- MockTransaction :: Eip4844 { max_fee_per_gas, .. } = self
417
- {
418
- Some ( * max_fee_per_gas)
419
- } else {
420
- None
415
+ match self {
416
+ MockTransaction :: Eip1559 { max_fee_per_gas, .. } |
417
+ MockTransaction :: Eip4844 { max_fee_per_gas, .. } => Some ( * max_fee_per_gas) ,
418
+ _ => None ,
421
419
}
422
420
}
423
421
424
422
/// Sets the access list for transactions supporting EIP-1559, EIP-4844, and EIP-2930.
425
423
pub fn set_accesslist ( & mut self , list : AccessList ) -> & mut Self {
426
424
match self {
427
425
MockTransaction :: Legacy { .. } => { }
428
- MockTransaction :: Eip1559 { accesslist, .. } => {
429
- * accesslist = list;
430
- }
431
- MockTransaction :: Eip4844 { accesslist, .. } => {
432
- * accesslist = list;
433
- }
426
+ MockTransaction :: Eip1559 { accesslist, .. } |
427
+ MockTransaction :: Eip4844 { accesslist, .. } |
434
428
MockTransaction :: Eip2930 { accesslist, .. } => {
435
429
* accesslist = list;
436
430
}
@@ -443,18 +437,15 @@ impl MockTransaction {
443
437
/// Sets the gas price for the transaction.
444
438
pub fn set_gas_price ( & mut self , val : u128 ) -> & mut Self {
445
439
match self {
446
- MockTransaction :: Legacy { gas_price, .. } => {
440
+ MockTransaction :: Legacy { gas_price, .. } |
441
+ MockTransaction :: Eip2930 { gas_price, .. } => {
447
442
* gas_price = val;
448
443
}
449
- MockTransaction :: Eip1559 { max_fee_per_gas, max_priority_fee_per_gas, .. } => {
450
- * max_fee_per_gas = val;
451
- * max_priority_fee_per_gas = val;
452
- }
444
+ MockTransaction :: Eip1559 { max_fee_per_gas, max_priority_fee_per_gas, .. } |
453
445
MockTransaction :: Eip4844 { max_fee_per_gas, max_priority_fee_per_gas, .. } => {
454
446
* max_fee_per_gas = val;
455
447
* max_priority_fee_per_gas = val;
456
448
}
457
- MockTransaction :: Eip2930 { gas_price, .. } => * gas_price = val,
458
449
#[ cfg( feature = "optimism" ) ]
459
450
MockTransaction :: Deposit ( _) => { }
460
451
}
@@ -464,17 +455,15 @@ impl MockTransaction {
464
455
/// Sets the gas price for the transaction.
465
456
pub fn with_gas_price ( mut self , val : u128 ) -> Self {
466
457
match self {
467
- MockTransaction :: Legacy { ref mut gas_price, .. } => {
458
+ MockTransaction :: Legacy { ref mut gas_price, .. } |
459
+ MockTransaction :: Eip2930 { ref mut gas_price, .. } => {
468
460
* gas_price = val;
469
461
}
470
462
MockTransaction :: Eip1559 {
471
463
ref mut max_fee_per_gas,
472
464
ref mut max_priority_fee_per_gas,
473
465
..
474
- } => {
475
- * max_fee_per_gas = val;
476
- * max_priority_fee_per_gas = val;
477
- }
466
+ } |
478
467
MockTransaction :: Eip4844 {
479
468
ref mut max_fee_per_gas,
480
469
ref mut max_priority_fee_per_gas,
@@ -483,9 +472,6 @@ impl MockTransaction {
483
472
* max_fee_per_gas = val;
484
473
* max_priority_fee_per_gas = val;
485
474
}
486
- MockTransaction :: Eip2930 { ref mut gas_price, .. } => {
487
- * gas_price = val;
488
- }
489
475
#[ cfg( feature = "optimism" ) ]
490
476
MockTransaction :: Deposit ( _) => { }
491
477
}
@@ -506,20 +492,17 @@ impl MockTransaction {
506
492
507
493
/// Returns a clone with a decreased nonce
508
494
pub fn prev ( & self ) -> Self {
509
- let next = self . clone ( ) . with_hash ( B256 :: random ( ) ) ;
510
- next. with_nonce ( self . get_nonce ( ) - 1 )
495
+ self . clone ( ) . with_hash ( B256 :: random ( ) ) . with_nonce ( self . get_nonce ( ) - 1 )
511
496
}
512
497
513
498
/// Returns a clone with an increased nonce
514
499
pub fn next ( & self ) -> Self {
515
- let next = self . clone ( ) . with_hash ( B256 :: random ( ) ) ;
516
- next. with_nonce ( self . get_nonce ( ) + 1 )
500
+ self . clone ( ) . with_hash ( B256 :: random ( ) ) . with_nonce ( self . get_nonce ( ) + 1 )
517
501
}
518
502
519
503
/// Returns a clone with an increased nonce
520
504
pub fn skip ( & self , skip : u64 ) -> Self {
521
- let next = self . clone ( ) . with_hash ( B256 :: random ( ) ) ;
522
- next. with_nonce ( self . get_nonce ( ) + skip + 1 )
505
+ self . clone ( ) . with_hash ( B256 :: random ( ) ) . with_nonce ( self . get_nonce ( ) + skip + 1 )
523
506
}
524
507
525
508
/// Returns a clone with incremented nonce
@@ -540,9 +523,7 @@ impl MockTransaction {
540
523
541
524
/// Returns a new transaction with a higher gas price
542
525
pub fn inc_price_by ( & self , value : u128 ) -> Self {
543
- let next = self . clone ( ) ;
544
- let gas = self . get_gas_price ( ) . checked_add ( value) . unwrap ( ) ;
545
- next. with_gas_price ( gas)
526
+ self . clone ( ) . with_gas_price ( self . get_gas_price ( ) . checked_add ( value) . unwrap ( ) )
546
527
}
547
528
548
529
/// Returns a new transaction with a lower gas price -1
@@ -552,23 +533,17 @@ impl MockTransaction {
552
533
553
534
/// Returns a new transaction with a lower gas price
554
535
pub fn decr_price_by ( & self , value : u128 ) -> Self {
555
- let next = self . clone ( ) ;
556
- let gas = self . get_gas_price ( ) . checked_sub ( value) . unwrap ( ) ;
557
- next. with_gas_price ( gas)
536
+ self . clone ( ) . with_gas_price ( self . get_gas_price ( ) . checked_sub ( value) . unwrap ( ) )
558
537
}
559
538
560
539
/// Returns a new transaction with a higher value
561
540
pub fn inc_value ( & self ) -> Self {
562
- let next = self . clone ( ) ;
563
- let val = self . get_value ( ) . checked_add ( U256 :: from ( 1 ) ) . unwrap ( ) ;
564
- next. with_value ( val)
541
+ self . clone ( ) . with_value ( self . get_value ( ) . checked_add ( U256 :: from ( 1 ) ) . unwrap ( ) )
565
542
}
566
543
567
544
/// Returns a new transaction with a higher gas limit
568
545
pub fn inc_limit ( & self ) -> Self {
569
- let next = self . clone ( ) ;
570
- let gas = self . get_gas_limit ( ) + 1 ;
571
- next. with_gas_limit ( gas)
546
+ self . clone ( ) . with_gas_limit ( self . get_gas_limit ( ) + 1 )
572
547
}
573
548
574
549
/// Returns the transaction type identifier associated with the current [MockTransaction].
@@ -607,9 +582,9 @@ impl MockTransaction {
607
582
impl PoolTransaction for MockTransaction {
608
583
fn hash ( & self ) -> & TxHash {
609
584
match self {
610
- MockTransaction :: Legacy { hash, .. } => hash ,
611
- MockTransaction :: Eip1559 { hash, .. } => hash ,
612
- MockTransaction :: Eip4844 { hash, .. } => hash ,
585
+ MockTransaction :: Legacy { hash, .. } |
586
+ MockTransaction :: Eip1559 { hash, .. } |
587
+ MockTransaction :: Eip4844 { hash, .. } |
613
588
MockTransaction :: Eip2930 { hash, .. } => hash,
614
589
#[ cfg( feature = "optimism" ) ]
615
590
MockTransaction :: Deposit ( TxDeposit { source_hash, .. } ) => source_hash,
@@ -618,9 +593,9 @@ impl PoolTransaction for MockTransaction {
618
593
619
594
fn sender ( & self ) -> Address {
620
595
match self {
621
- MockTransaction :: Legacy { sender, .. } => * sender ,
622
- MockTransaction :: Eip1559 { sender, .. } => * sender ,
623
- MockTransaction :: Eip4844 { sender, .. } => * sender ,
596
+ MockTransaction :: Legacy { sender, .. } |
597
+ MockTransaction :: Eip1559 { sender, .. } |
598
+ MockTransaction :: Eip4844 { sender, .. } |
624
599
MockTransaction :: Eip2930 { sender, .. } => * sender,
625
600
#[ cfg( feature = "optimism" ) ]
626
601
MockTransaction :: Deposit ( TxDeposit { from, .. } ) => * from,
@@ -629,9 +604,9 @@ impl PoolTransaction for MockTransaction {
629
604
630
605
fn nonce ( & self ) -> u64 {
631
606
match self {
632
- MockTransaction :: Legacy { nonce, .. } => * nonce ,
633
- MockTransaction :: Eip1559 { nonce, .. } => * nonce ,
634
- MockTransaction :: Eip4844 { nonce, .. } => * nonce ,
607
+ MockTransaction :: Legacy { nonce, .. } |
608
+ MockTransaction :: Eip1559 { nonce, .. } |
609
+ MockTransaction :: Eip4844 { nonce, .. } |
635
610
MockTransaction :: Eip2930 { nonce, .. } => * nonce,
636
611
#[ cfg( feature = "optimism" ) ]
637
612
MockTransaction :: Deposit ( _) => 0u64 ,
@@ -640,18 +615,14 @@ impl PoolTransaction for MockTransaction {
640
615
641
616
fn cost ( & self ) -> U256 {
642
617
match self {
643
- MockTransaction :: Legacy { gas_price, value, gas_limit, .. } => {
618
+ MockTransaction :: Legacy { gas_price, value, gas_limit, .. } |
619
+ MockTransaction :: Eip2930 { gas_limit, gas_price, value, .. } => {
644
620
U256 :: from ( * gas_limit) * U256 :: from ( * gas_price) + * value
645
621
}
646
- MockTransaction :: Eip1559 { max_fee_per_gas, value, gas_limit, .. } => {
647
- U256 :: from ( * gas_limit) * U256 :: from ( * max_fee_per_gas) + * value
648
- }
622
+ MockTransaction :: Eip1559 { max_fee_per_gas, value, gas_limit, .. } |
649
623
MockTransaction :: Eip4844 { max_fee_per_gas, value, gas_limit, .. } => {
650
624
U256 :: from ( * gas_limit) * U256 :: from ( * max_fee_per_gas) + * value
651
625
}
652
- MockTransaction :: Eip2930 { gas_limit, gas_price, value, .. } => {
653
- U256 :: from ( * gas_limit) * U256 :: from ( * gas_price) + * value
654
- }
655
626
#[ cfg( feature = "optimism" ) ]
656
627
MockTransaction :: Deposit ( _) => U256 :: ZERO ,
657
628
}
@@ -663,10 +634,10 @@ impl PoolTransaction for MockTransaction {
663
634
664
635
fn max_fee_per_gas ( & self ) -> u128 {
665
636
match self {
666
- MockTransaction :: Legacy { gas_price, .. } => * gas_price,
667
- MockTransaction :: Eip1559 { max_fee_per_gas, .. } => * max_fee_per_gas,
668
- MockTransaction :: Eip4844 { max_fee_per_gas, .. } => * max_fee_per_gas,
637
+ MockTransaction :: Legacy { gas_price, .. } |
669
638
MockTransaction :: Eip2930 { gas_price, .. } => * gas_price,
639
+ MockTransaction :: Eip1559 { max_fee_per_gas, .. } |
640
+ MockTransaction :: Eip4844 { max_fee_per_gas, .. } => * max_fee_per_gas,
670
641
#[ cfg( feature = "optimism" ) ]
671
642
MockTransaction :: Deposit ( _) => 0u128 ,
672
643
}
@@ -675,8 +646,8 @@ impl PoolTransaction for MockTransaction {
675
646
fn access_list ( & self ) -> Option < & AccessList > {
676
647
match self {
677
648
MockTransaction :: Legacy { .. } => None ,
678
- MockTransaction :: Eip1559 { accesslist : accessslist , .. } => Some ( accessslist ) ,
679
- MockTransaction :: Eip4844 { accesslist : accessslist , .. } => Some ( accessslist ) ,
649
+ MockTransaction :: Eip1559 { accesslist, .. } |
650
+ MockTransaction :: Eip4844 { accesslist, .. } |
680
651
MockTransaction :: Eip2930 { accesslist, .. } => Some ( accesslist) ,
681
652
#[ cfg( feature = "optimism" ) ]
682
653
MockTransaction :: Deposit ( _) => None ,
@@ -685,14 +656,11 @@ impl PoolTransaction for MockTransaction {
685
656
686
657
fn max_priority_fee_per_gas ( & self ) -> Option < u128 > {
687
658
match self {
688
- MockTransaction :: Legacy { .. } => None ,
689
- MockTransaction :: Eip1559 { max_priority_fee_per_gas, .. } => {
690
- Some ( * max_priority_fee_per_gas)
691
- }
659
+ MockTransaction :: Legacy { .. } | MockTransaction :: Eip2930 { .. } => None ,
660
+ MockTransaction :: Eip1559 { max_priority_fee_per_gas, .. } |
692
661
MockTransaction :: Eip4844 { max_priority_fee_per_gas, .. } => {
693
662
Some ( * max_priority_fee_per_gas)
694
663
}
695
- MockTransaction :: Eip2930 { .. } => None ,
696
664
#[ cfg( feature = "optimism" ) ]
697
665
MockTransaction :: Deposit ( _) => None ,
698
666
}
@@ -705,58 +673,74 @@ impl PoolTransaction for MockTransaction {
705
673
}
706
674
}
707
675
676
+ /// Calculates the effective tip per gas given a base fee.
708
677
fn effective_tip_per_gas ( & self , base_fee : u64 ) -> Option < u128 > {
678
+ // Convert base_fee to u128 for precision in calculations
709
679
let base_fee = base_fee as u128 ;
680
+
681
+ // Retrieve the maximum fee per gas
710
682
let max_fee_per_gas = self . max_fee_per_gas ( ) ;
683
+
684
+ // If the maximum fee per gas is less than the base fee, return None
711
685
if max_fee_per_gas < base_fee {
712
- return None
686
+ return None ;
713
687
}
714
688
689
+ // Calculate the fee by subtracting the base fee from the maximum fee per gas
715
690
let fee = max_fee_per_gas - base_fee;
691
+
692
+ // If the maximum priority fee per gas is available, return the minimum of fee and priority
693
+ // fee
716
694
if let Some ( priority_fee) = self . max_priority_fee_per_gas ( ) {
717
- return Some ( fee. min ( priority_fee) )
695
+ return Some ( fee. min ( priority_fee) ) ;
718
696
}
719
697
698
+ // Otherwise, return the calculated fee
720
699
Some ( fee)
721
700
}
722
701
702
+ /// Returns the priority fee or gas price based on the transaction type.
723
703
fn priority_fee_or_price ( & self ) -> u128 {
724
704
match self {
725
- MockTransaction :: Legacy { gas_price, .. } => * gas_price,
726
- MockTransaction :: Eip1559 { max_priority_fee_per_gas, .. } => * max_priority_fee_per_gas,
727
- MockTransaction :: Eip4844 { max_priority_fee_per_gas, .. } => * max_priority_fee_per_gas,
705
+ MockTransaction :: Legacy { gas_price, .. } |
728
706
MockTransaction :: Eip2930 { gas_price, .. } => * gas_price,
707
+ MockTransaction :: Eip1559 { max_priority_fee_per_gas, .. } |
708
+ MockTransaction :: Eip4844 { max_priority_fee_per_gas, .. } => * max_priority_fee_per_gas,
729
709
#[ cfg( feature = "optimism" ) ]
730
710
MockTransaction :: Deposit ( _) => 0u128 ,
731
711
}
732
712
}
733
713
714
+ /// Returns the transaction kind associated with the transaction.
734
715
fn kind ( & self ) -> & TransactionKind {
735
716
match self {
736
- MockTransaction :: Legacy { to, .. } => to ,
737
- MockTransaction :: Eip1559 { to, .. } => to ,
738
- MockTransaction :: Eip4844 { to, .. } => to ,
717
+ MockTransaction :: Legacy { to, .. } |
718
+ MockTransaction :: Eip1559 { to, .. } |
719
+ MockTransaction :: Eip4844 { to, .. } |
739
720
MockTransaction :: Eip2930 { to, .. } => to,
740
721
#[ cfg( feature = "optimism" ) ]
741
722
MockTransaction :: Deposit ( TxDeposit { to, .. } ) => to,
742
723
}
743
724
}
744
725
726
+ /// Returns the input data associated with the transaction.
745
727
fn input ( & self ) -> & [ u8 ] {
746
728
match self {
747
729
MockTransaction :: Legacy { .. } => & [ ] ,
748
- MockTransaction :: Eip1559 { input, .. } => input ,
749
- MockTransaction :: Eip4844 { input, .. } => input ,
730
+ MockTransaction :: Eip1559 { input, .. } |
731
+ MockTransaction :: Eip4844 { input, .. } |
750
732
MockTransaction :: Eip2930 { input, .. } => input,
751
733
#[ cfg( feature = "optimism" ) ]
752
734
MockTransaction :: Deposit { .. } => & [ ] ,
753
735
}
754
736
}
755
737
738
+ /// Returns the size of the transaction.
756
739
fn size ( & self ) -> usize {
757
740
0
758
741
}
759
742
743
+ /// Returns the transaction type as a byte identifier.
760
744
fn tx_type ( & self ) -> u8 {
761
745
match self {
762
746
MockTransaction :: Legacy { .. } => TxType :: Legacy . into ( ) ,
@@ -768,14 +752,17 @@ impl PoolTransaction for MockTransaction {
768
752
}
769
753
}
770
754
755
+ /// Returns the encoded length of the transaction.
771
756
fn encoded_length ( & self ) -> usize {
772
757
0
773
758
}
774
759
760
+ /// Returns the chain ID associated with the transaction.
775
761
fn chain_id ( & self ) -> Option < u64 > {
776
762
Some ( 1 )
777
763
}
778
764
765
+ /// Returns true if the transaction is a deposit transaction.
779
766
#[ cfg( feature = "optimism" ) ]
780
767
fn is_deposit ( & self ) -> bool {
781
768
matches ! ( self , MockTransaction :: Deposit ( _) )
@@ -1137,10 +1124,9 @@ impl MockTransactionFactory {
1137
1124
origin : TransactionOrigin ,
1138
1125
transaction : MockTransaction ,
1139
1126
) -> MockValidTx {
1140
- let transaction_id = self . tx_id ( & transaction) ;
1141
1127
MockValidTx {
1142
1128
propagate : false ,
1143
- transaction_id,
1129
+ transaction_id : self . tx_id ( & transaction ) ,
1144
1130
transaction,
1145
1131
timestamp : Instant :: now ( ) ,
1146
1132
origin,
0 commit comments