1
1
use anyhow:: { anyhow, Error } ;
2
2
use anyhow:: { ensure, Context } ;
3
+ use graph:: abi:: EventExt ;
4
+ use graph:: abi:: FunctionExt ;
3
5
use graph:: blockchain:: { BlockPtr , TriggerWithHandler } ;
4
6
use graph:: components:: metrics:: subgraph:: SubgraphInstanceMetrics ;
5
7
use graph:: components:: store:: { EthereumCallCache , StoredDynamicDataSource } ;
@@ -15,6 +17,10 @@ use graph::futures03::stream::FuturesOrdered;
15
17
use graph:: futures03:: TryStreamExt ;
16
18
use graph:: prelude:: ethabi:: ethereum_types:: H160 ;
17
19
use 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 ;
18
24
use graph:: prelude:: { Link , SubgraphManifestValidationError } ;
19
25
use graph:: slog:: { debug, error, o, trace} ;
20
26
use itertools:: Itertools ;
@@ -33,6 +39,7 @@ use graph::{
33
39
async_trait,
34
40
ethabi:: { Address , Event , Function , LogParam , ParamType , RawLog } ,
35
41
serde_json, warn,
42
+ async_trait, serde_json, warn,
36
43
web3:: types:: { Log , Transaction , H256 } ,
37
44
BlockNumber , CheapClone , EthereumCall , LightEthereumBlock , LightEthereumBlockExt ,
38
45
LinkResolver , Logger ,
@@ -525,28 +532,28 @@ impl DataSource {
525
532
}
526
533
}
527
534
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
529
536
/// will be matched if:
530
537
/// 1. An event signature is equal to `signature`.
531
538
/// 2. There are no equal matches, but there is exactly one event that equals `signature` if all
532
539
/// `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 > {
534
541
// 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 {
536
543
format ! (
537
544
"{}({})" ,
538
545
event. name,
539
546
event
540
547
. inputs
541
548
. iter( )
542
- . map( |input| event_param_type_signature ( & input. kind ) )
549
+ . map( |input| input. selector_type ( ) . into_owned ( ) )
543
550
. collect:: <Vec <_>>( )
544
551
. join( "," )
545
552
)
546
553
}
547
554
548
555
// 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 {
550
557
format ! (
551
558
"{}({})" ,
552
559
event. name,
@@ -556,40 +563,13 @@ impl DataSource {
556
563
. map( |input| format!(
557
564
"{}{}" ,
558
565
if input. indexed { "indexed " } else { "" } ,
559
- event_param_type_signature ( & input. kind )
566
+ input. selector_type ( )
560
567
) )
561
568
. collect:: <Vec <_>>( )
562
569
. join( "," )
563
570
)
564
571
}
565
572
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
-
593
573
self . contract_abi
594
574
. contract
595
575
. events ( )
@@ -628,7 +608,12 @@ impl DataSource {
628
608
} )
629
609
}
630
610
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
+
632
617
self . contract_abi
633
618
. contract
634
619
. functions ( )
@@ -642,7 +627,7 @@ impl DataSource {
642
627
let mut arguments = function
643
628
. inputs
644
629
. iter ( )
645
- . map ( |input| format ! ( "{}" , input. kind ) )
630
+ . map ( |input| format ! ( "{}" , input. selector_type ( ) ) )
646
631
. collect :: < Vec < String > > ( )
647
632
. join ( "," ) ;
648
633
// `address,uint256,bool)
@@ -732,11 +717,7 @@ impl DataSource {
732
717
. into_iter ( )
733
718
. filter_map ( |( event_handler, event_abi) | {
734
719
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)
740
721
. map_err ( |e| {
741
722
trace ! (
742
723
logger,
@@ -841,20 +822,15 @@ impl DataSource {
841
822
)
842
823
} ) ?;
843
824
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 ( || {
851
828
format ! (
852
829
"Generating function inputs for the call {:?} failed, raw input: {}" ,
853
830
& function_abi,
854
831
hex:: encode( & call. input. 0 )
855
832
)
856
- } ,
857
- ) {
833
+ } ) {
858
834
Ok ( val) => val,
859
835
// See also 280b0108-a96e-4738-bb37-60ce11eeb5bf
860
836
Err ( err) => {
@@ -864,27 +840,22 @@ impl DataSource {
864
840
} ;
865
841
866
842
ensure ! (
867
- tokens . len( ) == function_abi. inputs. len( ) ,
843
+ values . len( ) == function_abi. inputs. len( ) ,
868
844
"Number of arguments in call does not match \
869
845
number of inputs in function signature."
870
846
) ;
871
847
872
- let inputs = tokens
848
+ let inputs = values
873
849
. into_iter ( )
874
850
. enumerate ( )
875
- . map ( |( i, token ) | LogParam {
851
+ . map ( |( i, value ) | graph :: abi :: DynSolParam {
876
852
name : function_abi. inputs [ i] . name . clone ( ) ,
877
- value : token ,
853
+ value,
878
854
} )
879
855
. collect :: < Vec < _ > > ( ) ;
880
856
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 )
888
859
. with_context ( || {
889
860
format ! (
890
861
"Decoding function outputs for the call {:?} failed, raw output: {}" ,
@@ -894,17 +865,17 @@ impl DataSource {
894
865
} ) ?;
895
866
896
867
ensure ! (
897
- tokens . len( ) == function_abi. outputs. len( ) ,
868
+ values . len( ) == function_abi. outputs. len( ) ,
898
869
"Number of parameters in the call output does not match \
899
870
number of outputs in the function signature."
900
871
) ;
901
872
902
- let outputs = tokens
873
+ let outputs = values
903
874
. into_iter ( )
904
875
. enumerate ( )
905
- . map ( |( i, token ) | LogParam {
876
+ . map ( |( i, value ) | graph :: abi :: DynSolParam {
906
877
name : function_abi. outputs [ i] . name . clone ( ) ,
907
- value : token ,
878
+ value,
908
879
} )
909
880
. collect :: < Vec < _ > > ( ) ;
910
881
0 commit comments