@@ -31,8 +31,7 @@ use katana_rpc_client::starknet::{
3131} ;
3232use katana_rpc_types:: class:: Class ;
3333use katana_rpc_types:: {
34- ContractStorageKeys , GetBlockWithReceiptsResponse , GetStorageProofResponse , StateUpdate ,
35- TxReceiptWithBlockInfo ,
34+ ConfirmedBlockIdOrTag , ContractStorageKeys , GetBlockWithReceiptsResponse , GetStorageProofResponse , StateUpdate , TraceBlockTransactionsResponse , TxReceiptWithBlockInfo
3635} ;
3736use parking_lot:: Mutex ;
3837use tracing:: { error, trace} ;
@@ -349,6 +348,24 @@ impl Backend {
349348 }
350349 }
351350
351+ pub fn get_block_transactions_traces (
352+ & self ,
353+ block_id : BlockHashOrNumber ,
354+ ) -> Result < Option < TraceBlockTransactionsResponse > , BackendClientError > {
355+ trace ! ( block = %block_id, "Requesting trace block." ) ;
356+ let ( req, rx) = BackendRequest :: trace ( block_id) ;
357+ self . request ( req) ?;
358+ match rx. recv ( ) ? {
359+ BackendResponse :: TraceBlockTransactions ( res) => {
360+ if let Some ( res) = handle_not_found_err ( res) ? {
361+ Ok ( Some ( res) )
362+ } else {
363+ Ok ( None )
364+ }
365+ }
366+ response => Err ( BackendClientError :: UnexpectedResponse ( anyhow ! ( "{response:?}" ) ) ) ,
367+ }
368+ }
352369 /// Send a request to the backend thread.
353370 fn request ( & self , req : BackendRequest ) -> Result < ( ) , BackendClientError > {
354371 self . sender . lock ( ) . try_send ( req) . map_err ( |e| e. into_send_error ( ) ) ?;
@@ -383,6 +400,7 @@ enum BackendResponse {
383400 StorageRoot ( BackendResult < Felt > ) ,
384401 GlobalRoots ( BackendResult < GetStorageProofResponse > ) ,
385402 Proofs ( BackendResult < GetStorageProofResponse > ) ,
403+ TraceBlockTransactions ( BackendResult < TraceBlockTransactionsResponse > ) ,
386404}
387405
388406/// Errors that can occur when interacting with the backend.
@@ -423,6 +441,7 @@ enum BackendRequest {
423441 Nonce ( Request < ( ContractAddress , BlockNumber ) > ) ,
424442 ClassHash ( Request < ( ContractAddress , BlockNumber ) > ) ,
425443 Storage ( Request < ( ( ContractAddress , StorageKey ) , BlockNumber ) > ) ,
444+ Trace ( Request < BlockHashOrNumber > ) ,
426445}
427446
428447impl BackendRequest {
@@ -520,6 +539,11 @@ impl BackendRequest {
520539 let ( sender, receiver) = oneshot ( ) ;
521540 ( BackendRequest :: StorageRoot ( Request { payload : ( contract, block_id) , sender } ) , receiver)
522541 }
542+
543+ fn trace ( block_id : BlockHashOrNumber ) -> ( BackendRequest , OneshotReceiver < BackendResponse > ) {
544+ let ( sender, receiver) = oneshot ( ) ;
545+ ( BackendRequest :: Trace ( Request { payload : block_id, sender } ) , receiver)
546+ }
523547}
524548
525549type BackendRequestFuture = BoxFuture < ' static , BackendResponse > ;
@@ -538,6 +562,7 @@ enum BackendRequestIdentifier {
538562 Class ( ClassHash , BlockNumber ) ,
539563 ClassHash ( ContractAddress , BlockNumber ) ,
540564 Storage ( ( ContractAddress , StorageKey ) , BlockNumber ) ,
565+ Trace ( BlockHashOrNumber ) ,
541566}
542567
543568/// Metrics for the forking backend.
@@ -793,6 +818,25 @@ impl BackendWorker {
793818 } ) ,
794819 ) ;
795820 }
821+ BackendRequest :: Trace ( Request { payload : block_id, sender } ) => {
822+ let req_key = BackendRequestIdentifier :: Trace ( block_id) ;
823+ let block_id = match block_id {
824+ BlockHashOrNumber :: Hash ( h) => ConfirmedBlockIdOrTag :: Hash ( h) ,
825+ BlockHashOrNumber :: Num ( n) => ConfirmedBlockIdOrTag :: Number ( n) ,
826+ } ;
827+
828+ self . dedup_request (
829+ req_key,
830+ sender,
831+ Box :: pin ( async move {
832+ let result = provider
833+ . trace_block_transactions ( block_id)
834+ . await
835+ . map_err ( |e| BackendError :: StarknetProvider ( Arc :: new ( e) ) ) ;
836+ BackendResponse :: TraceBlockTransactions ( result)
837+ } ) ,
838+ ) ;
839+ }
796840 }
797841 }
798842
0 commit comments