@@ -74,45 +74,60 @@ impl AccountChangesBuilder {
7474 }
7575
7676 /// Consumes the builder and produces [`AccountChanges`]
77+ ///
78+ /// Sorting per FAL spec: storage keys lexicographic, block_access_index ascending
7779 pub fn build ( mut self , address : Address ) -> AccountChanges {
80+ let mut storage_changes: Vec < _ > = self
81+ . storage_changes
82+ . drain ( )
83+ . map ( |( slot, sc) | {
84+ let mut changes: Vec < _ > = sc
85+ . into_iter ( )
86+ . map ( |( tx_idx, val) | StorageChange {
87+ block_access_index : tx_idx,
88+ new_value : val. into ( ) ,
89+ } )
90+ . collect ( ) ;
91+ changes. sort_unstable_by_key ( |c| c. block_access_index ) ;
92+ SlotChanges { slot : slot. into ( ) , changes }
93+ } )
94+ . collect ( ) ;
95+ storage_changes. sort_unstable_by_key ( |sc| sc. slot ) ;
96+
97+ let mut storage_reads: Vec < _ > = self . storage_reads . into_iter ( ) . collect ( ) ;
98+ storage_reads. sort_unstable ( ) ;
99+
100+ let mut balance_changes: Vec < _ > = self
101+ . balance_changes
102+ . into_iter ( )
103+ . map ( |( tx_idx, val) | BalanceChange { block_access_index : tx_idx, post_balance : val } )
104+ . collect ( ) ;
105+ balance_changes. sort_unstable_by_key ( |c| c. block_access_index ) ;
106+
107+ let mut nonce_changes: Vec < _ > = self
108+ . nonce_changes
109+ . into_iter ( )
110+ . map ( |( tx_idx, val) | NonceChange { block_access_index : tx_idx, new_nonce : val } )
111+ . collect ( ) ;
112+ nonce_changes. sort_unstable_by_key ( |c| c. block_access_index ) ;
113+
114+ let mut code_changes: Vec < _ > = self
115+ . code_changes
116+ . into_iter ( )
117+ . map ( |( tx_idx, bc) | CodeChange {
118+ block_access_index : tx_idx,
119+ new_code : bc. original_bytes ( ) ,
120+ } )
121+ . collect ( ) ;
122+ code_changes. sort_unstable_by_key ( |c| c. block_access_index ) ;
123+
78124 AccountChanges {
79125 address,
80- storage_changes : self
81- . storage_changes
82- . drain ( )
83- . map ( |( slot, sc) | SlotChanges {
84- slot : slot. into ( ) ,
85- changes : sc
86- . into_iter ( )
87- . map ( |( tx_idx, val) | StorageChange {
88- block_access_index : tx_idx,
89- new_value : val. into ( ) ,
90- } )
91- . collect ( ) ,
92- } )
93- . collect ( ) ,
94- storage_reads : self . storage_reads . into_iter ( ) . collect ( ) ,
95- balance_changes : self
96- . balance_changes
97- . into_iter ( )
98- . map ( |( tx_idx, val) | BalanceChange {
99- block_access_index : tx_idx,
100- post_balance : val,
101- } )
102- . collect ( ) ,
103- nonce_changes : self
104- . nonce_changes
105- . into_iter ( )
106- . map ( |( tx_idx, val) | NonceChange { block_access_index : tx_idx, new_nonce : val } )
107- . collect ( ) ,
108- code_changes : self
109- . code_changes
110- . into_iter ( )
111- . map ( |( tx_idx, bc) | CodeChange {
112- block_access_index : tx_idx,
113- new_code : bc. original_bytes ( ) ,
114- } )
115- . collect ( ) ,
126+ storage_changes,
127+ storage_reads,
128+ balance_changes,
129+ nonce_changes,
130+ code_changes,
116131 }
117132 }
118133}
0 commit comments