11use anyhow:: { anyhow, Error } ;
22use anyhow:: { ensure, Context } ;
3+ use graph:: abi:: EventExt ;
4+ use graph:: abi:: FunctionExt ;
35use graph:: blockchain:: { BlockPtr , TriggerWithHandler } ;
46use graph:: components:: metrics:: subgraph:: SubgraphInstanceMetrics ;
57use graph:: components:: store:: { EthereumCallCache , StoredDynamicDataSource } ;
@@ -15,6 +17,10 @@ use graph::futures03::stream::FuturesOrdered;
1517use graph:: futures03:: TryStreamExt ;
1618use graph:: prelude:: ethabi:: ethereum_types:: H160 ;
1719use graph:: prelude:: ethabi:: StateMutability ;
20+ use graph:: prelude:: lazy_static;
21+ use graph:: prelude:: regex:: Regex ;
22+ use graph:: prelude:: web3:: types:: Address ;
23+ use graph:: prelude:: web3:: types:: H160 ;
1824use graph:: prelude:: { Link , SubgraphManifestValidationError } ;
1925use graph:: slog:: { debug, error, o, trace} ;
2026use itertools:: Itertools ;
@@ -33,6 +39,7 @@ use graph::{
3339 async_trait,
3440 ethabi:: { Address , Event , Function , LogParam , ParamType , RawLog } ,
3541 serde_json, warn,
42+ async_trait, serde_json, warn,
3643 web3:: types:: { Log , Transaction , H256 } ,
3744 BlockNumber , CheapClone , EthereumCall , LightEthereumBlock , LightEthereumBlockExt ,
3845 LinkResolver , Logger ,
@@ -525,28 +532,28 @@ impl DataSource {
525532 }
526533 }
527534
528- /// Returns the contract event with the given signature, if it exists. A an event from the ABI
535+ /// Returns the contract event with the given signature, if it exists. An event from the ABI
529536 /// will be matched if:
530537 /// 1. An event signature is equal to `signature`.
531538 /// 2. There are no equal matches, but there is exactly one event that equals `signature` if all
532539 /// `indexed` modifiers are removed from the parameters.
533- fn contract_event_with_signature ( & self , signature : & str ) -> Option < & Event > {
540+ fn contract_event_with_signature ( & self , signature : & str ) -> Option < & graph :: abi :: Event > {
534541 // Returns an `Event(uint256,address)` signature for an event, without `indexed` hints.
535- fn ambiguous_event_signature ( event : & Event ) -> String {
542+ fn ambiguous_event_signature ( event : & graph :: abi :: Event ) -> String {
536543 format ! (
537544 "{}({})" ,
538545 event. name,
539546 event
540547 . inputs
541548 . iter( )
542- . map( |input| event_param_type_signature ( & input. kind ) )
549+ . map( |input| input. selector_type ( ) . into_owned ( ) )
543550 . collect:: <Vec <_>>( )
544551 . join( "," )
545552 )
546553 }
547554
548555 // Returns an `Event(indexed uint256,address)` type signature for an event.
549- fn event_signature ( event : & Event ) -> String {
556+ fn event_signature ( event : & graph :: abi :: Event ) -> String {
550557 format ! (
551558 "{}({})" ,
552559 event. name,
@@ -556,40 +563,13 @@ impl DataSource {
556563 . map( |input| format!(
557564 "{}{}" ,
558565 if input. indexed { "indexed " } else { "" } ,
559- event_param_type_signature ( & input. kind )
566+ input. selector_type ( )
560567 ) )
561568 . collect:: <Vec <_>>( )
562569 . join( "," )
563570 )
564571 }
565572
566- // Returns the signature of an event parameter type (e.g. `uint256`).
567- fn event_param_type_signature ( kind : & ParamType ) -> String {
568- use ParamType :: * ;
569-
570- match kind {
571- Address => "address" . into ( ) ,
572- Bytes => "bytes" . into ( ) ,
573- Int ( size) => format ! ( "int{}" , size) ,
574- Uint ( size) => format ! ( "uint{}" , size) ,
575- Bool => "bool" . into ( ) ,
576- String => "string" . into ( ) ,
577- Array ( inner) => format ! ( "{}[]" , event_param_type_signature( inner) ) ,
578- FixedBytes ( size) => format ! ( "bytes{}" , size) ,
579- FixedArray ( inner, size) => {
580- format ! ( "{}[{}]" , event_param_type_signature( inner) , size)
581- }
582- Tuple ( components) => format ! (
583- "({})" ,
584- components
585- . iter( )
586- . map( event_param_type_signature)
587- . collect:: <Vec <_>>( )
588- . join( "," )
589- ) ,
590- }
591- }
592-
593573 self . contract_abi
594574 . contract
595575 . events ( )
@@ -628,7 +608,12 @@ impl DataSource {
628608 } )
629609 }
630610
631- fn contract_function_with_signature ( & self , target_signature : & str ) -> Option < & Function > {
611+ fn contract_function_with_signature (
612+ & self ,
613+ target_signature : & str ,
614+ ) -> Option < & graph:: abi:: Function > {
615+ use graph:: abi:: StateMutability ;
616+
632617 self . contract_abi
633618 . contract
634619 . functions ( )
@@ -642,7 +627,7 @@ impl DataSource {
642627 let mut arguments = function
643628 . inputs
644629 . iter ( )
645- . map ( |input| format ! ( "{}" , input. kind ) )
630+ . map ( |input| format ! ( "{}" , input. selector_type ( ) ) )
646631 . collect :: < Vec < String > > ( )
647632 . join ( "," ) ;
648633 // `address,uint256,bool)
@@ -732,11 +717,7 @@ impl DataSource {
732717 . into_iter ( )
733718 . filter_map ( |( event_handler, event_abi) | {
734719 event_abi
735- . parse_log ( RawLog {
736- topics : log. topics . clone ( ) ,
737- data : log. data . clone ( ) . 0 ,
738- } )
739- . map ( |log| log. params )
720+ . decode_log ( & log)
740721 . map_err ( |e| {
741722 trace ! (
742723 logger,
@@ -841,20 +822,15 @@ impl DataSource {
841822 )
842823 } ) ?;
843824
844- // Parse the inputs
845- //
846- // Take the input for the call, chop off the first 4 bytes, then call
847- // `function.decode_input` to get a vector of `Token`s. Match the `Token`s
848- // with the `Param`s in `function.inputs` to create a `Vec<LogParam>`.
849- let tokens = match function_abi. decode_input ( & call. input . 0 [ 4 ..] ) . with_context (
850- || {
825+ let values = match function_abi
826+ . abi_decode_input ( & call. input . 0 [ 4 ..] )
827+ . with_context ( || {
851828 format ! (
852829 "Generating function inputs for the call {:?} failed, raw input: {}" ,
853830 & function_abi,
854831 hex:: encode( & call. input. 0 )
855832 )
856- } ,
857- ) {
833+ } ) {
858834 Ok ( val) => val,
859835 // See also 280b0108-a96e-4738-bb37-60ce11eeb5bf
860836 Err ( err) => {
@@ -864,27 +840,22 @@ impl DataSource {
864840 } ;
865841
866842 ensure ! (
867- tokens . len( ) == function_abi. inputs. len( ) ,
843+ values . len( ) == function_abi. inputs. len( ) ,
868844 "Number of arguments in call does not match \
869845 number of inputs in function signature."
870846 ) ;
871847
872- let inputs = tokens
848+ let inputs = values
873849 . into_iter ( )
874850 . enumerate ( )
875- . map ( |( i, token ) | LogParam {
851+ . map ( |( i, value ) | graph :: abi :: DynSolParam {
876852 name : function_abi. inputs [ i] . name . clone ( ) ,
877- value : token ,
853+ value,
878854 } )
879855 . collect :: < Vec < _ > > ( ) ;
880856
881- // Parse the outputs
882- //
883- // Take the output for the call, then call `function.decode_output` to
884- // get a vector of `Token`s. Match the `Token`s with the `Param`s in
885- // `function.outputs` to create a `Vec<LogParam>`.
886- let tokens = function_abi
887- . decode_output ( & call. output . 0 )
857+ let values = function_abi
858+ . abi_decode_output ( & call. output . 0 )
888859 . with_context ( || {
889860 format ! (
890861 "Decoding function outputs for the call {:?} failed, raw output: {}" ,
@@ -894,17 +865,17 @@ impl DataSource {
894865 } ) ?;
895866
896867 ensure ! (
897- tokens . len( ) == function_abi. outputs. len( ) ,
868+ values . len( ) == function_abi. outputs. len( ) ,
898869 "Number of parameters in the call output does not match \
899870 number of outputs in the function signature."
900871 ) ;
901872
902- let outputs = tokens
873+ let outputs = values
903874 . into_iter ( )
904875 . enumerate ( )
905- . map ( |( i, token ) | LogParam {
876+ . map ( |( i, value ) | graph :: abi :: DynSolParam {
906877 name : function_abi. outputs [ i] . name . clone ( ) ,
907- value : token ,
878+ value,
908879 } )
909880 . collect :: < Vec < _ > > ( ) ;
910881
0 commit comments