@@ -583,19 +583,20 @@ impl BundleState {
583
583
self . reverts . push ( reverts) ;
584
584
}
585
585
586
- /// Consume the bundle state and return plain state.
587
- pub fn into_plain_state ( self , is_value_known : OriginalValuesKnown ) -> StateChangeset {
586
+ /// Generate a [`StateChangeset`] from the bundle state without consuming
587
+ /// it.
588
+ pub fn to_plain_state ( & self , is_value_known : OriginalValuesKnown ) -> StateChangeset {
588
589
// pessimistically pre-allocate assuming _all_ accounts changed.
589
590
let state_len = self . state . len ( ) ;
590
591
let mut accounts = Vec :: with_capacity ( state_len) ;
591
592
let mut storage = Vec :: with_capacity ( state_len) ;
592
593
593
- for ( address, account) in self . state {
594
+ for ( address, account) in self . state . iter ( ) {
594
595
// append account info if it is changed.
595
596
let was_destroyed = account. was_destroyed ( ) ;
596
597
if is_value_known. is_not_known ( ) || account. is_info_changed ( ) {
597
- let info = account. info . map ( AccountInfo :: without_code ) ;
598
- accounts. push ( ( address, info) ) ;
598
+ let info = account. info . as_ref ( ) . map ( AccountInfo :: copy_without_code ) ;
599
+ accounts. push ( ( * address, info) ) ;
599
600
}
600
601
601
602
// append storage changes
@@ -604,7 +605,7 @@ impl BundleState {
604
605
// database so we can check if plain state was wiped or not.
605
606
let mut account_storage_changed = Vec :: with_capacity ( account. storage . len ( ) ) ;
606
607
607
- for ( key, slot) in account. storage {
608
+ for ( key, slot) in account. storage . iter ( ) . map ( | ( k , v ) | ( * k , * v ) ) {
608
609
// If storage was destroyed that means that storage was wiped.
609
610
// In that case we need to check if present storage value is different then ZERO.
610
611
let destroyed_and_not_zero = was_destroyed && !slot. present_value . is_zero ( ) ;
@@ -624,17 +625,19 @@ impl BundleState {
624
625
if !account_storage_changed. is_empty ( ) || was_destroyed {
625
626
// append storage changes to account.
626
627
storage. push ( PlainStorageChangeset {
627
- address,
628
+ address : * address ,
628
629
wipe_storage : was_destroyed,
629
630
storage : account_storage_changed,
630
631
} ) ;
631
632
}
632
633
}
634
+
633
635
let contracts = self
634
636
. contracts
635
- . into_iter ( )
637
+ . iter ( )
636
638
// remove empty bytecodes
637
- . filter ( |( b, _) | * b != KECCAK_EMPTY )
639
+ . filter ( |( b, _) | * * b != KECCAK_EMPTY )
640
+ . map ( |( b, code) | ( * b, code. clone ( ) ) )
638
641
. collect :: < Vec < _ > > ( ) ;
639
642
StateChangeset {
640
643
accounts,
@@ -643,14 +646,32 @@ impl BundleState {
643
646
}
644
647
}
645
648
646
- /// Consume the bundle state and split it into reverts and plain state.
649
+ /// Convert the bundle state into a [`StateChangeset`].
650
+ #[ deprecated = "Use `to_plain_state` instead" ]
651
+ pub fn into_plain_state ( self , is_value_known : OriginalValuesKnown ) -> StateChangeset {
652
+ self . to_plain_state ( is_value_known)
653
+ }
654
+
655
+ /// Generate a [`StateChangeset`] and [`PlainStateReverts`] from the bundle
656
+ /// state.
657
+ pub fn to_plain_state_and_reverts (
658
+ & self ,
659
+ is_value_known : OriginalValuesKnown ,
660
+ ) -> ( StateChangeset , PlainStateReverts ) {
661
+ (
662
+ self . to_plain_state ( is_value_known) ,
663
+ self . reverts . to_plain_state_reverts ( ) ,
664
+ )
665
+ }
666
+
667
+ /// Consume the bundle state and split it into a [`StateChangeset`] and a
668
+ /// [`PlainStateReverts`].
669
+ #[ deprecated = "Use `to_plain_state_and_reverts` instead" ]
647
670
pub fn into_plain_state_and_reverts (
648
- mut self ,
671
+ self ,
649
672
is_value_known : OriginalValuesKnown ,
650
673
) -> ( StateChangeset , PlainStateReverts ) {
651
- let reverts = self . take_all_reverts ( ) ;
652
- let plain_state = self . into_plain_state ( is_value_known) ;
653
- ( plain_state, reverts. into_plain_state_reverts ( ) )
674
+ self . to_plain_state_and_reverts ( is_value_known)
654
675
}
655
676
656
677
/// Extend the bundle with other state
0 commit comments