11#[ rustfmt:: skip]
2+ #[ allow( clippy:: doc_lazy_continuation, clippy:: doc_overindented_list_items) ]
23#[ path = "protobuf/sf.ethereum.r#type.v2.rs" ]
34mod pbcodec;
45
@@ -844,6 +845,33 @@ impl BlockchainBlock for HeaderOnlyBlock {
844845 }
845846}
846847
848+ fn extract_signature_from_trace (
849+ _trace : & TransactionTrace ,
850+ _tx_type : TxType ,
851+ ) -> Result < alloy:: signers:: Signature , Error > {
852+ use alloy:: primitives:: { Signature as PrimitiveSignature , U256 } ;
853+
854+ // Create a dummy signature with r = 0, s = 0 and even y-parity (false)
855+ let dummy = PrimitiveSignature :: new ( U256 :: ZERO , U256 :: ZERO , false ) ;
856+
857+ Ok ( dummy)
858+ }
859+
860+ fn get_to_address ( trace : & TransactionTrace ) -> Result < Option < Address > , Error > {
861+ // Try to detect contract creation transactions, which have no 'to' address
862+ let is_contract_creation = trace. to . is_empty ( )
863+ || trace
864+ . calls
865+ . first ( )
866+ . is_some_and ( |call| CallType :: try_from ( call. call_type ) == Ok ( CallType :: Create ) ) ;
867+
868+ if is_contract_creation {
869+ Ok ( None )
870+ } else {
871+ Ok ( Some ( trace. to . try_decode_proto ( "transaction to address" ) ?) )
872+ }
873+ }
874+
847875#[ cfg( test) ]
848876mod test {
849877 use graph:: { blockchain:: Block as _, prelude:: chrono:: Utc } ;
@@ -886,25 +914,31 @@ mod test {
886914 use graph:: prelude:: alloy:: network:: AnyTxEnvelope ;
887915 use graph:: prelude:: alloy:: primitives:: B256 ;
888916
889- let mut block = Block :: default ( ) ;
890- let mut header = BlockHeader :: default ( ) ;
891- header. number = 123456 ;
892- header. timestamp = Some ( Timestamp {
893- seconds : 1234567890 ,
894- nanos : 0 ,
895- } ) ;
896- block. header = Some ( header) ;
897- block. number = 123456 ;
898- block. hash = vec ! [ 0u8 ; 32 ] ;
899-
900- let mut trace = TransactionTrace :: default ( ) ;
901- trace. r#type = 126 ; // 0x7e Optimism deposit transaction
902- trace. hash = vec ! [ 1u8 ; 32 ] ;
903- trace. from = vec ! [ 2u8 ; 20 ] ;
904- trace. to = vec ! [ 3u8 ; 20 ] ;
905- trace. nonce = 42 ;
906- trace. gas_limit = 21000 ;
907- trace. index = 0 ;
917+ let header = BlockHeader {
918+ number : 123456 ,
919+ timestamp : Some ( Timestamp {
920+ seconds : 1234567890 ,
921+ nanos : 0 ,
922+ } ) ,
923+ ..Default :: default ( )
924+ } ;
925+ let block = Block {
926+ header : Some ( header) ,
927+ number : 123456 ,
928+ hash : vec ! [ 0u8 ; 32 ] ,
929+ ..Default :: default ( )
930+ } ;
931+
932+ let trace = TransactionTrace {
933+ r#type : 126 , // 0x7e Optimism deposit transaction
934+ hash : vec ! [ 1u8 ; 32 ] ,
935+ from : vec ! [ 2u8 ; 20 ] ,
936+ to : vec ! [ 3u8 ; 20 ] ,
937+ nonce : 42 ,
938+ gas_limit : 21000 ,
939+ index : 0 ,
940+ ..Default :: default ( )
941+ } ;
908942
909943 let trace_at = TransactionTraceAt :: new ( & trace, & block) ;
910944 let result: Result <
@@ -941,25 +975,32 @@ mod test {
941975 use super :: transaction_trace_to_alloy_txn_reciept;
942976 use crate :: codec:: TransactionTrace ;
943977
944- let mut block = Block :: default ( ) ;
945- let mut header = BlockHeader :: default ( ) ;
946- header. number = 123456 ;
947- block. header = Some ( header) ;
948- block. hash = vec ! [ 0u8 ; 32 ] ;
949-
950- let mut trace = TransactionTrace :: default ( ) ;
951- trace. r#type = 126 ; // 0x7e Optimism deposit transaction
952- trace. hash = vec ! [ 1u8 ; 32 ] ;
953- trace. from = vec ! [ 2u8 ; 20 ] ;
954- trace. to = vec ! [ 3u8 ; 20 ] ;
955- trace. index = 0 ;
956- trace. gas_used = 21000 ;
957- trace. status = 1 ;
958-
959- let mut receipt = super :: TransactionReceipt :: default ( ) ;
960- receipt. cumulative_gas_used = 21000 ;
961- receipt. logs_bloom = vec ! [ 0u8 ; 256 ] ;
962- trace. receipt = Some ( receipt) ;
978+ let header = BlockHeader {
979+ number : 123456 ,
980+ ..Default :: default ( )
981+ } ;
982+ let block = Block {
983+ header : Some ( header) ,
984+ hash : vec ! [ 0u8 ; 32 ] ,
985+ ..Default :: default ( )
986+ } ;
987+
988+ let receipt = super :: TransactionReceipt {
989+ cumulative_gas_used : 21000 ,
990+ logs_bloom : vec ! [ 0u8 ; 256 ] ,
991+ ..Default :: default ( )
992+ } ;
993+ let trace = TransactionTrace {
994+ r#type : 126 , // 0x7e Optimism deposit transaction
995+ hash : vec ! [ 1u8 ; 32 ] ,
996+ from : vec ! [ 2u8 ; 20 ] ,
997+ to : vec ! [ 3u8 ; 20 ] ,
998+ index : 0 ,
999+ gas_used : 21000 ,
1000+ status : 1 ,
1001+ receipt : Some ( receipt) ,
1002+ ..Default :: default ( )
1003+ } ;
9631004
9641005 let result = transaction_trace_to_alloy_txn_reciept ( & trace, & block) ;
9651006
@@ -978,30 +1019,3 @@ mod test {
9781019 assert_eq ! ( receipt. transaction_index, Some ( 0 ) ) ;
9791020 }
9801021}
981-
982- fn extract_signature_from_trace (
983- _trace : & TransactionTrace ,
984- _tx_type : TxType ,
985- ) -> Result < alloy:: signers:: Signature , Error > {
986- use alloy:: primitives:: { Signature as PrimitiveSignature , U256 } ;
987-
988- // Create a dummy signature with r = 0, s = 0 and even y-parity (false)
989- let dummy = PrimitiveSignature :: new ( U256 :: ZERO , U256 :: ZERO , false ) ;
990-
991- Ok ( dummy)
992- }
993-
994- fn get_to_address ( trace : & TransactionTrace ) -> Result < Option < Address > , Error > {
995- // Try to detect contract creation transactions, which have no 'to' address
996- let is_contract_creation = trace. to . is_empty ( )
997- || trace
998- . calls
999- . first ( )
1000- . is_some_and ( |call| CallType :: try_from ( call. call_type ) == Ok ( CallType :: Create ) ) ;
1001-
1002- if is_contract_creation {
1003- Ok ( None )
1004- } else {
1005- Ok ( Some ( trace. to . try_decode_proto ( "transaction to address" ) ?) )
1006- }
1007- }
0 commit comments