@@ -160,23 +160,18 @@ where
160160/// In old transactions, the resource bounds names are lowercase.
161161/// Need to convert to uppercase for deserialization to work.
162162fn upper_case_resource_bounds_names ( raw_transaction : & mut Value ) {
163- let resource_bounds = raw_transaction
164- . get_mut ( "resource_bounds" )
165- . expect ( "tx should contain resource_bounds field" )
166- . as_object_mut ( )
167- . expect ( "resource_bounds should be an object" ) ;
168-
169- if let Some ( l1_gas_value) = resource_bounds. remove ( "l1_gas" ) {
170- resource_bounds. insert ( "L1_GAS" . to_string ( ) , l1_gas_value) ;
171-
172- let l2_gas_value = resource_bounds
173- . remove ( "l2_gas" )
174- . expect ( "If tx contains l1_gas, it should contain l2_gas" ) ;
175- resource_bounds. insert ( "L2_GAS" . to_string ( ) , l2_gas_value) ;
176- }
163+ let Some ( resource_bounds) =
164+ raw_transaction. get_mut ( "resource_bounds" ) . and_then ( Value :: as_object_mut)
165+ else {
166+ return ;
167+ } ;
177168
178- if let Some ( l1_data_gas_value) = resource_bounds. remove ( "l1_data_gas" ) {
179- resource_bounds. insert ( "L1_DATA_GAS" . to_string ( ) , l1_data_gas_value) ;
169+ for ( lower_case_name, upper_case_name) in
170+ [ ( "l1_gas" , "L1_GAS" ) , ( "l2_gas" , "L2_GAS" ) , ( "l1_data_gas" , "L1_DATA_GAS" ) ]
171+ {
172+ if let Some ( resource_bounds_value) = resource_bounds. remove ( lower_case_name) {
173+ resource_bounds. insert ( upper_case_name. to_string ( ) , resource_bounds_value) ;
174+ }
180175 }
181176}
182177
0 commit comments