@@ -66,7 +66,6 @@ impl Dataset for Transactions {
6666 "n_input_bytes" ,
6767 "n_input_zero_bytes" ,
6868 "n_input_nonzero_bytes" ,
69- "n_rlp_bytes" ,
7069 "chain_id" ,
7170 ] )
7271 }
@@ -143,13 +142,15 @@ impl CollectByBlock for Transactions {
143142 let schema = query. schemas . get_schema ( & Datatype :: Transactions ) ?;
144143 let ( block, transactions_with_receipts, exclude_failed) = response;
145144 for ( tx, receipt) in transactions_with_receipts. into_iter ( ) {
145+ let gas_price = get_gas_price ( & block, & tx) ;
146146 process_transaction (
147147 tx,
148148 receipt,
149149 columns,
150150 schema,
151151 exclude_failed,
152152 block. header . timestamp as u32 ,
153+ gas_price
153154 ) ?;
154155 }
155156 Ok ( ( ) )
@@ -158,7 +159,7 @@ impl CollectByBlock for Transactions {
158159
159160#[ async_trait:: async_trait]
160161impl CollectByTransaction for Transactions {
161- type Response = ( TransactionAndReceipt , bool , u32 ) ;
162+ type Response = ( TransactionAndReceipt , Block , bool , u32 ) ;
162163
163164 async fn extract ( request : Params , source : Arc < Source > , query : Arc < Query > ) -> R < Self :: Response > {
164165 let tx_hash = request. ethers_transaction_hash ( ) ?;
@@ -184,13 +185,22 @@ impl CollectByTransaction for Transactions {
184185
185186 let timestamp = block. header . timestamp as u32 ;
186187
187- Ok ( ( ( transaction, receipt) , query. exclude_failed , timestamp) )
188+ Ok ( ( ( transaction, receipt) , block , query. exclude_failed , timestamp) )
188189 }
189190
190191 fn transform ( response : Self :: Response , columns : & mut Self , query : & Arc < Query > ) -> R < ( ) > {
191192 let schema = query. schemas . get_schema ( & Datatype :: Transactions ) ?;
192- let ( ( transaction, receipt) , exclude_failed, timestamp) = response;
193- process_transaction ( transaction, receipt, columns, schema, exclude_failed, timestamp) ?;
193+ let ( ( transaction, receipt) , block, exclude_failed, timestamp) = response;
194+ let gas_price = get_gas_price ( & block, & transaction) ;
195+ process_transaction (
196+ transaction,
197+ receipt,
198+ columns,
199+ schema,
200+ exclude_failed,
201+ timestamp,
202+ gas_price
203+ ) ?;
194204 Ok ( ( ) )
195205 }
196206}
@@ -202,6 +212,7 @@ pub(crate) fn process_transaction(
202212 schema : & Table ,
203213 exclude_failed : bool ,
204214 timestamp : u32 ,
215+ gas_price : Option < u64 > ,
205216) -> R < ( ) > {
206217 let success = if exclude_failed | schema. has_column ( "success" ) {
207218 let success = tx_success ( & tx, & receipt) ?;
@@ -244,10 +255,11 @@ pub(crate) fn process_transaction(
244255 }
245256 // in alloy eip2718_encoded_length is rlp_encoded_length
246257 store ! ( schema, columns, n_rlp_bytes, tx. inner. eip2718_encoded_length( ) as u32 ) ;
247- store ! ( schema, columns, gas_used, receipt. map( |r| r. gas_used as u64 ) ) ;
248- store ! ( schema, columns, gas_price, tx. inner. gas_price( ) . map( |gas_price| gas_price as u64 ) ) ;
258+ store ! ( schema, columns, gas_used, receipt. as_ref( ) . map( |r| r. gas_used as u64 ) ) ;
259+ // store!(schema, columns, gas_price, Some(receipt.unwrap().effective_gas_price as u64));
260+ store ! ( schema, columns, gas_price, gas_price) ;
249261 store ! ( schema, columns, transaction_type, tx. inner. tx_type( ) as u32 ) ;
250- store ! ( schema, columns, max_fee_per_gas, Some ( tx . inner . max_fee_per_gas ( ) as u64 ) ) ;
262+ store ! ( schema, columns, max_fee_per_gas, get_max_fee_per_gas ( & tx ) ) ;
251263 store ! (
252264 schema,
253265 columns,
@@ -264,6 +276,29 @@ pub(crate) fn process_transaction(
264276 Ok ( ( ) )
265277}
266278
279+ fn get_max_fee_per_gas ( tx : & Transaction ) -> Option < u64 > {
280+ match & tx. inner {
281+ alloy:: consensus:: TxEnvelope :: Legacy ( _) => None ,
282+ alloy:: consensus:: TxEnvelope :: Eip2930 ( _) => None ,
283+ _ => Some ( tx. inner . max_fee_per_gas ( ) as u64 ) ,
284+ }
285+ }
286+
287+ pub ( crate ) fn get_gas_price ( block : & Block , tx : & Transaction ) -> Option < u64 > {
288+ match & tx. inner {
289+ alloy:: consensus:: TxEnvelope :: Legacy ( _) => tx. gas_price ( ) . map ( |gas_price| gas_price as u64 ) ,
290+ alloy:: consensus:: TxEnvelope :: Eip2930 ( _) => tx. gas_price ( ) . map ( |gas_price| gas_price as u64 ) ,
291+ _ => {
292+ let base_fee_per_gas = block. header . inner . base_fee_per_gas . unwrap ( ) ;
293+ let priority_fee = std:: cmp:: min (
294+ tx. inner . max_priority_fee_per_gas ( ) . unwrap ( ) as u64 ,
295+ tx. inner . max_fee_per_gas ( ) as u64 - base_fee_per_gas,
296+ ) ;
297+ Some ( base_fee_per_gas + priority_fee)
298+ }
299+ }
300+ }
301+
267302fn tx_success ( tx : & Transaction , receipt : & Option < TransactionReceipt > ) -> R < bool > {
268303 if let Some ( r) = receipt {
269304 Ok ( r. status ( ) )
0 commit comments